Skip to content

Commit 89a411c

Browse files
committed
Flush implementation more like zlibmodule.c
1 parent f966514 commit 89a411c

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

src/isal/isal_zlib.pyx

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,6 @@ cdef class Compress:
469469
return b""
470470
elif mode == zlib.Z_FINISH:
471471
self.stream.flush = FULL_FLUSH
472-
self.stream.end_of_stream = 1
473472
elif mode == zlib.Z_FULL_FLUSH:
474473
self.stream.flush = FULL_FLUSH
475474
elif mode == zlib.Z_SYNC_FLUSH:
@@ -493,10 +492,16 @@ cdef class Compress:
493492
# the data is appended to a list.
494493
# TODO: Improve this with the buffer protocol.
495494
out.append(self.obuf[:self.obuflen - self.stream.avail_out])
496-
if self.stream.internal_state.state != ZSTATE_END and mode == zlib.Z_FINISH:
497-
continue
498-
elif self.stream.avail_in == 0:
499-
break
495+
496+
if self.stream.avail_out != 0: # All input is processed and therefore all output flushed.
497+
if self.stream.internal_state.state != ZSTATE_END and mode == zlib.Z_FINISH:
498+
# If mode ==zlib.Z_FINISH we do one more round to finish the stream.
499+
self.stream.end_of_stream = 1
500+
continue
501+
else:
502+
break
503+
if self.stream.avail_in != 0:
504+
raise AssertionError("There should be no available input after flushing.")
500505
return b"".join(out)
501506

502507
cdef class Decompress:

0 commit comments

Comments
 (0)