ZLIB decompressing only portion of data

mkx at excite.com mkx at excite.com
Wed Feb 21 11:24:26 EST 2001


On Wed, 21 Feb 2001 06:23:14 GMT, "Fredrik Lundh"
<fredrik at pythonware.com> wrote:

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

This methodology still only returns the first segment of uncompressed
data.

So far, only the following works, returning about 12K of uncompressed
data, before returning an Error -3 while decompressing: unknown
compression method.

###

import zlib

fd=open('d:/temp/zlb/snippets.zlb', 'rb' )
of=open('d:/temp/zlb/snippets.dat','w')

dco = zlib.decompressobj()
str = dco.decompress(fd.read(16384))
of.write(str)

while dco.unused_data:
    ustr = dco.unused_data
    dco=zlib.decompressobj()	# Having to recreate the dco object
				# each time, otherwise further data 
				# not returned
    str=dco.decompress(ustr)
    of.write(str)





More information about the Python-list mailing list