Forums > Javascript

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

October 11, 2011 | 9:57 pm

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.



jic
June 18, 2013 | 11:41 am

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!


Viewing 2 posts - 1 through 2 (of 2 total)