zlib problems with Python 2.0

Peter van der Kamp vdkamp at inter.nl.net
Sun Aug 19 05:49:32 EDT 2001


Hello,

Working with the zlib module under Python 2.0, OS/2 Warp 4,
I encounter the following error: unknown compression method.
Documentation, Internet, trial and error didn't solve the problem.
My script does the following.
Read chunks of text from a text file (I have good reasons not to 
compress
the complete file, so I won't explain that here). Split the chunk into
separate words. For every word register the number of the chunk.
Compress the chunk and write the compressed chunk to a file. For
every compressed chunk register its length and start position
within the file. So far no problem.
When I retrieve compressed chunks from the file, only the first
two are decompressed without problems. The remaining chunks return
the 'unknown compression method' error.

The relevant statements involved with compressing are (mixed up
with some pseudo-code):

import zlib

z = open("d:\\z.dat", "w")
for every chunk of text:
	zPar = zlib.compress(par, 9)
	print "Compressed: ", repr(zPar)
	z.write(zPar)
z.close()

The relevant statements involved with decompressing are (mixed up
with some pseudo-code):

z = open("d:\\z.dat", "r")
for every chunk of compressed text:
	z.seek(begin,0) #begin = the start position of the chunk within file
	zPar = z.read(lengte)  #lengte = length of compressed chunk
	uzPar = zlib.decompress(zPar)
	print uzPar
z.close()

Anyone any idea what goes wrong?

Thanks,

Peter van der Kamp




More information about the Python-list mailing list