while True:
    buf = z.unconsumed_tail
if buf == '':
    buf = f.read(1024)
if buf == '':
    break
got = z.decompress(buf, 4096)
if got == '':
    break
total += len(got)
print(total)
if z.unused_data != '' or f.read(1024) != '':
    pass
How to protect myself from a gzip or bzip2 bomb?