Re: Generate 16+MAX_WBITS decompressable data

Discussion in 'Python' started by Terry Reedy, Feb 12, 2013.

  1. Terry Reedy

    Terry Reedy Guest

    On 2/12/2013 7:47 AM, Fayaz Yusuf Khan wrote:
    > I'm trying write unit-tests for some of my old code and have run into this
    > piece of code.
    >
    > dcomp = zlib.decompressobj(16+zlib.MAX_WBITS)


    Since zlib.MAX_WBITS is the largest value that should be passed (15),
    adding 16 makes no sense. Since it is also the default, there is also no
    point in providing it explicitly. "Its absolute value should be between
    8 and 15 for the most recent versions of the zlib library".

    > chunk = ''.join(f.chunks())
    > received_data = dcomp.decompress(chunk)


    Since decompressobj is intended for data that will not all fit in memory
    at once, and since chunk does, just use zlib.decompress(chunk)

    > How do I generate the chunk here? From what I've been trying I'm getting
    > this exception:
    >>>> import zlib
    >>>> zlib.compress('hello')

    > 'x\x9c\xcbH\xcd\xc9\xc9\x07\x00\x06,\x02\x15'
    >>>> zlib.decompress(_, 16+zlib.MAX_WBITS)

    > Traceback (most recent call last):
    > File "<stdin>", line 1, in <module>
    > zlib.error: Error -3 while decompressing data: incorrect header check


    You asked for an internal buffer of 2**31 = 2 gigabytes.

    > zlib.decompress without the second argument works, but I can't really go
    > ahead into my project file and remove it.


    --
    Terry Jan Reedy
     
    Terry Reedy, Feb 12, 2013
    #1
    1. Advertising

  2. Marc Christiansen wrote:

    > Try using a compressobj with 24 <= wbits < 32. It should work, but I
    > didn't try.
    >

    Er, the problem is that compressobj doesn't accept a WBIT argument.
    --
    Fayaz Yusuf Khan
    Cloud architect, Dexetra SS, India
    fayaz.yusuf.khan_AT_gmail_DOT_com, fayaz_AT_dexetra_DOT_com
    +91-9746-830-823
     
    Fayaz Yusuf Khan, Feb 13, 2013
    #2
    1. Advertising

  3. Terry Reedy

    Terry Reedy Guest

    On 2/13/2013 12:18 AM, Fayaz Yusuf Khan wrote:
    > Marc Christiansen wrote:
    >
    >> Try using a compressobj with 24 <= wbits < 32. It should work, but I
    >> didn't try.
    >>

    > Er, the problem is that compressobj doesn't accept a WBIT argument.


    "Changed in version 3.3: Added the method, wbits, memlevel, strategy and
    zdict parameters."

    --
    Terry Jan Reedy
     
    Terry Reedy, Feb 13, 2013
    #3
    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. C T
    Replies:
    3
    Views:
    2,459
    Charles M. Elias
    Mar 5, 2004
  2. Weng Tianxiang
    Replies:
    5
    Views:
    1,332
    Christophe
    Feb 16, 2006
  3. Replies:
    3
    Views:
    423
    red floyd
    Apr 7, 2006
  4. Harlan Messinger
    Replies:
    2
    Views:
    2,324
    John Bell
    Mar 28, 2010
  5. Fayaz Yusuf Khan

    Generate 16+MAX_WBITS decompressable data

    Fayaz Yusuf Khan, Feb 12, 2013, in forum: Python
    Replies:
    0
    Views:
    176
    Fayaz Yusuf Khan
    Feb 12, 2013
Loading...

Share This Page