python zlib produces a -3 error when inflating data through a Decompress() object -
i have created decoder parse, decompress , extract single file zlib encoded file downloaded through urllib2 file-like object. idea utilize little memory , disk space possible, using reader / writer pattern "decoder" in middle uncompress data coming urllib2, feed cpio subprocess , write file data disk:
with closing(builder.open()) reader: open(component, "w+b") writer: decoder = decoder() while true: data = reader.read(10240) if len(data) == 0: break writer.write(decoder.decode(data)) final = decoder.flush() if final not none: writer.write(final) writer.flush()
the decoder pretty simple too:
class decoder(object): def __init__(self): self.__zcat = zlib.decompressobj() # cpio initialisation def decode(self, data_in): return self.__consume(self.__zcat.decompress(data_in)) def __consume(self, zcat_data_in): # cpio operations return data_out def flush(self): return self.__consume(self.__zcat.flush())
i seeing error before passed cpio pipe, felt omitting here sensible clarity.
the interesting thing, verify data in fact uncompressed zlib, wrote raw data data_in
being passed decode()
stdout:
def decode(self, data_in): sys.stdout.write(data_in) return self.__consume(self.__zcat.decompress(data_in))
then ran:
$ bin/myprog.py 2>/dev/null | zcat - | file - /dev/stdin: cpio archive
as can see, zcat quite happy data given on stdin , resultant file cpio archive. zlib decompress method reporting:
error: error -3 while decompressing: incorrect header check
\x1f\x9d
first 2 bytes of old unix compress format. zlib can't decompress it. gzip can decompress compatible old compress utility.
you can pull the code pigz decompressing format , use directly.
Comments
Post a Comment