zlib.decompress fails, zlib.decompressobj succeeds - bug or feature?

Matthew Brett matthew.brett at gmail.com
Sun May 9 04:28:14 EDT 2010


Hi,

I sorry if this is a bad place to ask, but I wanted to find out if the
behavior I'm seeing is a bug.

I maintain scipy's matlab file readers, and I came across a zlib
compressed string that causes a zlib error on decompression, but only
with zlib.decompress, not zlib.decompressobj.

I saved the original compressed string as a binary file at
http://dl.dropbox.com/u/794947/mat.bin

Now if I do:

import zlib
data = open('mat.bin', 'rb').read()
out = zlib.decompress(data)

I get an error : Error -5 while decompressing data)

If instead I do this:

out = zlib.decompressobj().decompress(data)

I get a usable uncompressed string.   I was expecting these two calls
to do the same thing.   Is that expectation right?  If not, is there
somewhere I could find out why?

Thanks a lot,

Matthew



More information about the Python-list mailing list