lua-compress-deflatelua
lua-compress-deflatelua copied to clipboard
Fail decompress python zlib compression
Hi
This is more a question than an issue. We are trying to use your library, which works great with your example, but failing to decompress python zlib compression. for example:
zlib.compress("hello world") #python code 'x\x9c\xcbH\xcd\xc9\xc9W(\xcf/\xcaI\x01\x00\x1a\x0b\x04]' #output
trying to decompress the above output produce an error.
Also tried to use zlib Huffman only compression:
zlib.compressobj(9, zlib.DEFLATED, 10, 8, zlib.Z_HUFFMAN_ONLY) '(\x15\xcaH\xcd\xc9\xc9W(\xcf/\xcaI\x01\x00\x00\x00\xff\xff'
but failed with that as well.
Do you have any idea what are we doing wrong?
Thanks!
A small update, i found this:
http://stackoverflow.com/questions/1089662/python-inflate-and-deflate-implementations
which explains;
According to RFC 1950, a zlib stream constructed in the default manner is comprised of:
a 2-byte header (e.g. 0x78 0x9C) a deflate stream -- see RFC 1951 an Adler-32 checksum of the uncompressed data (4 bytes)
So i tried to take the deflate stream and run the code on it which failed. also tried it with the header and without the checksum which also failed.
It fails on:
if (cmf*256 + flg) % 31 ~= 0 then runtime_error("invalid zlib header (bad fcheck sum)") end
Any thoughts?
Ok we manage to do it eventually. if anyone in the future want to do it in python just use: base64.encodestring(zlib.compress(data)[2:-4])
and decode it with lua before running through the library code.