I have a buffer of bytes read from a library call and I would like to unzip the content which is a single text file.
I tried with zlib
, but I get this error:
>>> import zlib
>>> zlib.decompress(buffer)
error: Error -3 while decompressing data: incorrect header check
However with ZipFile
it works, but I have to use a temporary file:
import zipfile
f = open('foo.zip', 'wb')
f.write(buffer)
f.close()
z = ZipFile('foo.zip')
z.extractall()
z.close()
with open('foo.txt', 'r') as f:
uncompressed_buffer = f.read()
Is it possible to use zlib
and how can I avoid using a temporary file?