zlib.decompress cannot, gunzip can

E

enrio

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
 
D

Dima Dorfman

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:

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

enrio

Thanks, now the code is

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

Regards, Enrique
 

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,733
Messages
2,569,440
Members
44,830
Latest member
ZADIva7383

Latest Threads

Top