I had downloaded a .gz file and decompressed it successfully using 'gzip -d'. But it went wrong when I tried to decompress it using python zlib by chunk.
CHUNK = 1024 * 1024
infile = open('2019-07-06-13.log.gz')
d = zlib.decompressobj(32 + zlib.MAX_WBITS)
while True:
chunk = infile.read(CHUNK)
if not chunk:
break
data = d.decompress(chunk)
print len(chunk), len(data)
print "#####"
Since the file is small, this loop will only run a time. The print result that "len(data)" is smaller than "len(chunk)" is certainly wrong.
The output:
100576 50389
#####
Meanwhile, after I used gzip -c to recompress the decompressed file I created by using "gzip -d" as I said before, I used my code to decompress the recompressed file and the resulting lens turned to be to right, which means my code works well for the normal gz file.