ZLIB decompressing only portion of data

Fredrik Lundh fredrik at pythonware.com
Wed Feb 21 01:23:14 EST 2001


mkx at excite.com wrote:
> Of course, there is a better way to implement my test script (see
> below), but I still get the same results. The input sample is 9,859
> bytes long, where the string returned by the decompress method is only
> 546 bytes in length.

what's wrong with using "open" like everyone else?

> import os, zlib
>
> fd=os.open('d:/temp/zlb/snippets.zlb', os.O_RDONLY | os.O_BINARY )

file = open("d:/temp/zlb/snippets.zlb", "rb")

> dco=zlib.decompressobj(15)

dco = zlib.decompressobj() # 15 is default

> str=dco.decompress(os.read(fd,16384))

str = dco.decompress(file.read(16384))
str = str + dco.flush() # get rest of data

> print len(str)
> #print str

for more info on decompress/flush, see the docs (under
"decompression objects"):

http://www.python.org/doc/current/lib/module-zlib.html

(and of course, if the files are smaller than a couple of megabytes
uncompressed, it's better to use zlib.decompress...)

Cheers /F





More information about the Python-list mailing list