pierrec / node-lz4

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

Decompressing Blocks w/ Invalid Returned Size #89

Open ghost opened 4 years ago

ghost commented 4 years ago

Hello, I just started using the library and can almost get it to work correctly. I have LZ4 blocks coming in as Base64 strings and I decode them with: data = new Buffer(input,'base64'); var output = new Buffer(data.length*10); var size = lz4.decodeBlock(data,output);

The returned 'size' is < 0 so there seems to be an error, but when I dump the results of 'output' to the console part of the original data is there properly decompressed. So it seems to be doing something right. Increasing the size of the buffer gets closer to showing the desired output, but is missing the last few characters. ('size' still < 0)

If I change the code to: var output = new Buffer(data.length*100); var size = lz4.decodeBlock(data,output,0,data.length*100);

I see the entire decompressed data, but also some extra garbage characters at the end of the output. 'size' still < 0. I tried multiple variations of the different properties and tried running the same data through a different .NET LZ4 library and it works as expected. I also tried using the 'size' in different ways with slice, but no luck in trimming the trailing characters.

Any ideas on what might be happening here? Feels like I'm missing something simple.

Thanks in advance for any help.