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

Discussion in 'Python' started by Matthew Brett, May 9, 2010.

  1. 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
     
    Matthew Brett, May 9, 2010
    #1
    1. Advertising

  2. Re: zlib.decompress fails, zlib.decompressobj succeeds - bug orfeature?

    On Sun, 9 May 2010 01:28:14 -0700 (PDT)
    Matthew Brett <> wrote:
    >
    > 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â€.
     
    Antoine Pitrou, May 9, 2010
    #2
    1. Advertising

  3. Re: zlib.decompress fails, zlib.decompressobj succeeds - bug orfeature?

    Hi,

    Thanks for the reply.

    > > If instead I do this:

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

    >
    > 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
     
    Matthew Brett, May 9, 2010
    #3
  4. Re: zlib.decompress fails, zlib.decompressobj succeeds - bug orfeature?

    On Sun, 9 May 2010 09:25:16 -0700 (PDT)
    Matthew Brett <> wrote:
    > > 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?


    Yes.

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


    Hmm, then it's a bug. Can you report it to http://bugs.python.org ?

    Thank you

    Antoine.
     
    Antoine Pitrou, May 9, 2010
    #4
  5. Re: zlib.decompress fails, zlib.decompressobj succeeds - bug orfeature?

    Hi,

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

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

    >
    > Hmm, then it's a bug. Can you report it tohttp://bugs.python.org?


    I will - thanks for your advice,

    Matthew
     
    Matthew Brett, May 9, 2010
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    2
    Views:
    1,315
  2. shabda raaj
    Replies:
    1
    Views:
    2,847
    Diez B. Roggisch
    Sep 10, 2007
  3. Steve Edlefsen

    can't decompress data; zlib not available

    Steve Edlefsen, Nov 13, 2011, in forum: Python
    Replies:
    0
    Views:
    662
    Steve Edlefsen
    Nov 13, 2011
  4. Steve Edlefsen
    Replies:
    0
    Views:
    578
    Steve Edlefsen
    Nov 14, 2011
  5. noname005
    Replies:
    0
    Views:
    238
    noname005
    Feb 18, 2013
Loading...

Share This Page