Problem
I\'m creating multiple charts that are then sent to the server to create a PDF. This data can get large.
Question>
I finally got this working with fairly large files.
To do it, I used lz-string
, as shown above.
There is one issue though, which is that sending UTF-16 data via ajax is deprecated, so.. it doesn't work. The fix is to convert to and from UTF-16 and UTF-8.
Here's the conversion code I'm using. I'm not sure what the standard endian is, btw:
var UTF = {};
UTF.U16to8 = function(convertMe) {
var out = "";
for(var i = 0; i < convertMe.length; i++) {
var charCode = convertMe.charCodeAt(i);
out += String.fromCharCode(~~(charCode/256));
out += String.fromCharCode(charCode%256);
}
return out;
}
UTF.U8to16 = function(convertMe) {
var out = ""
for(var i = 0; i < convertMe.length; i += 2) {
var charCode = convertMe.charCodeAt(i)*256;
charCode += convertMe.charCodeAt(i+1);
out += String.fromCharCode(charCode)
}
return out;
}
If you're using Node.js, this code works on both sides. If not, you'll have to write your own version of these converters for the server side.
Phew! What a day this was.