z = zlib.decompressobj()
while True:
    buf = z.unconsumed_tail
if buf == '':
    buf = f.read(8192)
if buf == '':
    break
got = z.decompress(buf)
if got == '':
    break
g.write(got)
How to inflate a partial zlib file