pierrec / node-lz4

LZ4 fast compression algorithm for NodeJS
MIT License
438 stars 98 forks source link

IE 9 : encodeBlock with byte == 268 ? #20

Closed iccube-real closed 9 years ago

iccube-real commented 10 years ago

Debugging an issue with sending compressed strings over the network, I'm facing the following issue in IE 9 only; IE 10+ , Chrome , Firefox look fine.

Here is the Javascript string to compress:

var value = "{\"classID\":\"ic3.ReportGuts\",\"guts_\":{\"ic3Version\":8,\"schemaName\":\"Sales\",\"cubeName\":\"Sales\",\"layout\":{\"classID\":\"ic3.FixedLayout\",\"guts_\":{\"ic3Version\":8,\"grid\":10,\"boxes\":[{\"classID\":\"ic3.FixedLayoutBox\",\"guts_\":{\"ic3Version\":8,\"header\":\"widget-0 ( HTML/HTML Box )\",\"behaviour\":\"Fixed Box\",\"noPrint\":false,\"position\":{\"top\":20,\"left\":20,\"width\":530,\"height\":130}";

I compress it using the following code:

var input = new Buffer(value);
var encodeBound = LZ4.encodeBound(input.length);
var output = new Buffer(encodeBound);
var compressedSize = LZ4.encodeBlock(input, output);
output = output.slice(0, compressedSize);

Then to debug the content of the buffer I'm writing to the DOM each byte as following:

$('body').append("<div><pre>len:" + output.length + "</pre></div>");
var out = "";
for (var ii = 0; ii < output.length; ii++) {
   out += ( "\n" + output[ii] );
}
$('body').append("<div><pre>" + out + "</pre></div>");
$('body').append("<div><pre>_</pre></div>");

And to my surprise, I'm seeing one line with _268_ which looks like an overflow. Am I doing something wrong here ?

Decompressing this buffer in IE 9 is OK and gives back the original string; but I need to send that data over the network to save it compressed. For that purpose I'm doing an output.toString( 'base64' ) first which I believe does not expect such a value.

Am I doing something wrong with the compressing / base64 logic ? or is that an issue with LZ4 on IE 9 ?

Thx, _marc

pierrec commented 9 years ago

Very late reply... This is because of the way the string is converted to an array. It' fine.