zlib.decompress cannot, gunzip can

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • enrio@online.no

    zlib.decompress cannot, gunzip can

    I have a string which I try to decompress:

    body = zlib.decompress (body)

    but I get

    zlib.error: Error -3 while decompressing data: incorrect header check

    However, I can write the string to a file and run gunzip with the
    expected results:

    f = open('/tmp/bd.gz', 'w')
    f.write(body)
    f.close
    ....
    $ gunzip bd.gz
    $ less bd

    What should I do to decompress it in Python?

    Regards, Enrique

  • Dima Dorfman

    #2
    Re: zlib.decompress cannot, gunzip can

    On 2005-03-01, enrio@online.no <enrio@online.n o> wrote:[color=blue]
    > I have a string which I try to decompress:
    >
    > body = zlib.decompress (body)
    >
    > but I get
    >
    > zlib.error: Error -3 while decompressing data: incorrect header check
    >
    > However, I can write the string to a file and run gunzip with the
    > expected results:[/color]

    gzip files have a header preceding the zlib stream. Try the gzip module.

    Comment

    • enrio@online.no

      #3
      Re: zlib.decompress cannot, gunzip can

      Thanks, now the code is

      from cStringIO import StringIO
      from gzip import GzipFile
      ...
      body = GzipFile('','r' ,0,StringIO(bod y)).read()

      Regards, Enrique

      Comment

      Working...