Reputation: 27012
I'm writing a DEFLATE uncompressor (in Python), and wanting to test it with Type 01 blocks (i.e. with the fixed Huffman code in of 3.2.6. of RFC 1951.
I know I can create them myself, but I would like to test it with blocks created by some other code, e.g. zlib. How can I do this? So far from my testing, zlib has always created Type 02 blocks (i.e. dynamic Huffman codes), or Type 00 blocks (not compressed).
(This is ultimately to be used in an unZIP code)
Upvotes: 2
Views: 427
Reputation: 27012
Ah found out how: passing strategy=zlib.Z_FIXED
to compressobj
import zlib
compressobj = zlib.compressobj(wbits=-zlib.MAX_WBITS, strategy=zlib.Z_FIXED)
compressed_stream = compressobj.compress(b'Some data') + compressobj.flush()
Upvotes: 1