javascriptnode.jszlibinflate

zlib inflate without DICTID and ADLER32 checksum nodejs


i am trying to inflate a buffer with the zlib module in NodeJs. I had the problem that i always got the "unexpected end of file" error so i used my original data and let nodejs deflate it to compare the byte values.

(1) So this is the value that i have:

120, 156, 106, 46, 97, 96, 96, 96, 73, 97, 96, 76, 1, 49, 152, 82, 24, 216, 226, 75, 138, 18, 147, 83, 115, 128, 60, 198, 92, 32, 161, 17, 173, 148, 158, 88, 146, 90, 158, 88, 169, 91, 80, 148, 162, 155, 155, 152, 153, 167, 91, 104, 96, 94, 172, 164, 83, 173, 148, 155, 153, 92, 148, 95, 172, 100, 101, 160, 103, 80, 27, 155, 149, 194, 32, 148, 145, 154, 88, 84, 146, 148, 154, 88, 18, 159, 153, 87, 146, 90, 84, 150, 152, 147, 196, 192, 176, 80, 41, 133, 129, 41, 191, 32, 145, 11, 104, 75, 113, 10, 3, 115, 94, 102, 14, 144, 85, 2, 97, 1, 0, 0, 0, 255, 255

(2) And this is what zlib.deflateSync gave me:

120, 156, 1, 125, 0, 130, 255, 120, 156, 106, 46, 97, 96, 96, 96, 73, 97, 96, 76, 1, 49, 152, 82, 24, 216, 226, 75, 138, 18, 147, 83, 115, 128, 60, 198, 92, 32, 161, 17, 173, 148, 158, 88, 146, 90, 158, 88, 169, 91, 80, 148, 162, 155, 155, 152, 153, 167, 91, 104, 96, 94, 172, 164, 83, 173, 148, 155, 153, 92, 148, 95, 172, 100, 101, 160, 103, 80, 27, 155, 149, 194, 32, 148, 145, 154, 88, 84, 146, 148, 154, 88, 18, 159, 153, 87, 146, 90, 84, 150, 152, 147, 196, 192, 176, 80, 41, 133, 129, 41, 191, 32, 145, 11, 104, 75, 113, 10, 3, 115, 94, 102, 14, 144, 85, 2, 97, 1, 0, 0, 0, 255, 255, 164, 112, 54, 45, (bold = same)

So as far as i can tell from the RFC the first two bytes are the compression method and flags and therefor both have it. The other bold part is the compressed data. So far so good.

The first part that doesn't match is the DICTID part. But according to the RFC it is only four bytes long so what are the other three bytes (255, 120, 156)? The last part that is not bold is the ADLER32 checksum of the compressed data.

Question: Is zlib (nodejs) somehow able to inflate data without the DICTID and ADLER32 checksum?

Current Code Snippet:

const data = /* Array from (1) */;
const buffer = Buffer.from(data);
const out = zlib.inflateSync(buffer);

Output: Error: unexpected end of file

Background: What i am ultimately trying to do is the following but in javascript instead of python.

Note: The command line program zlib-flate is somehow able to inflate the bytes from (1) so i am assuming i do something wrong.


Solution

  • After hours of trail and error i finally figured it out what the problem was. To be able to inflate the bytes from (1) you have to set the finishFlush option:

    const result = zlib.inflateSync(buffer, {finishFlush: zlib.constants.Z_SYNC_FLUSH});