[sharing is fun] 32K limit on File.writeline() method – how to get around it.

Oct 11, 2011 at 9:57pm

[sharing is fun] 32K limit on File.writeline() method – how to get around it.

I spent a LOT of time today on this, so I’m hoping to save some future Max’er the pain. If you try to use the writeline() method in the JavaScript File object, you’ll find you can only write a line upto 32K. The attached example demonstrates how to break up a string into chunks that can be written to a text file of any length.
I came across this problem when trying to save JSON files, which can very easily result in a very large string!
Patch and javascript are in this zip:

http://lividinstruments.com/dl/textlimits.zip

Peter
http://lividinstruments.com
Controllers, video software, all Max-friendly.

#59261
Jun 18, 2013 at 11:41am

Wonderful! This is exactly what I needed. Thanks for this.

I found a bug in that if the length is not perfectly divisible by the limit, it leaves off the remainder at the very end. This was fixed by adding the following line after the for loop (line 25):

fout.writestring(tojson.substring((breaks*lim), len));

cheers!

#253146

You must be logged in to reply to this topic.