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

M

Matthew Brett

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
 
A

Antoine Pitrou

If instead I do this:

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

How about:

d = zlib.decompressobj()
out = d.decompress(data) + d.flush()

?

Notice the documentation for decompressobj.decompress (emphasis mine):

“Decompress string, returning a string containing the uncompressed data
corresponding to *at least part* of the data in stringâ€.
 
M

Matthew Brett

Hi,

Thanks for the reply.
How about:

d = zlib.decompressobj()
out = d.decompress(data) + d.flush()

Do you mean, that you would then expect the decompressobj method to
fail as well?

But, no, d.flush() returns the empty string after decompressing
``data``.

Thanks again,

Matthew
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top