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

Peter Nyboer's icon

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's icon

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!

efiocco's icon

after a few days smashing my head on the keyboard I found this thread, thank you so much!!!