Decompression with zlib

Emma Li at
Wed Apr 8 23:51:22 CEST 2009


I'm trying to do compression/decompression of stuff with zlib, and I  
just don't get it...
Here is an example. I assume that dec should be "a", but it isn't. dec  
turns out to be an empty string, and I don't understand why...

import zlib
compressor = zlib.compressobj(6) # level
decompressor = zlib.decompressobj() # wbits

cmpr = compressor.compress("a")
print "compressed", len(cmpr)
dec = decompressor.decompress(cmpr)
print "decompressed", len(dec)

# unconsumed tail and unused data
print "decompressor.unconsumed_tail", decompressor.unconsumed_tail
##print "decompressor.unused_data", decompressor.unused_data

dec += decompressor.flush()
print "after flushing", len(dec)

Any help is appreciated.

More information about the Python-list mailing list