@@ -69,9 +69,10 @@ ISAL_NO_FLUSH=NO_FLUSH
69
69
ISAL_SYNC_FLUSH= SYNC_FLUSH
70
70
ISAL_FULL_FLUSH= FULL_FLUSH
71
71
72
- Z_NO_FLUSH= ISAL_NO_FLUSH
73
- Z_SYNC_FLUSH= ISAL_SYNC_FLUSH
74
- Z_FINISH= ISAL_FULL_FLUSH
72
+ Z_NO_FLUSH= zlib.Z_NO_FLUSH
73
+ Z_SYNC_FLUSH= zlib.Z_SYNC_FLUSH
74
+ Z_FULL_FLUSH= zlib.Z_FULL_FLUSH
75
+ Z_FINISH= zlib.Z_FINISH
75
76
76
77
class IsalError (OSError ):
77
78
""" Exception raised on compression and decompression errors."""
@@ -452,27 +453,34 @@ cdef class Compress:
452
453
finally :
453
454
PyBuffer_Release(buffer )
454
455
455
- def flush (self , int mode = FULL_FLUSH ):
456
+ def flush (self , mode = zlib.Z_FINISH ):
456
457
"""
457
458
All pending input is processed, and a bytes object containing the
458
459
remaining compressed output is returned.
459
460
460
- :param mode: Defaults to ISAL_FULL_FLUSH ( Z_FINISH equivalent) which
461
+ :param mode: Defaults to Z_FINISH which
461
462
finishes the compressed stream and prevents compressing
462
- any more data. The only other supported method is
463
- ISAL_SYNC_FLUSH ( Z_SYNC_FLUSH) equivalent .
463
+ any more data. The only other supported methods are
464
+ Z_SYNC_FLUSH and Z_FULL_FLUSH .
464
465
"""
465
- if mode == NO_FLUSH:
466
+
467
+ if mode == zlib.Z_NO_FLUSH:
466
468
# Flushing with no_flush does nothing.
467
469
return b" "
468
-
469
- self .stream.end_of_stream = 1
470
- self .stream.flush = mode
470
+ elif mode == zlib.Z_FINISH:
471
+ self .stream.flush = FULL_FLUSH
472
+ self .stream.end_of_stream = 1
473
+ elif mode == zlib.Z_FULL_FLUSH:
474
+ self .stream.flush = FULL_FLUSH
475
+ elif mode == zlib.Z_SYNC_FLUSH:
476
+ self .stream.flush= SYNC_FLUSH
477
+ else :
478
+ raise IsalError(" Unsupported flush mode" )
471
479
472
480
# Initialise output buffer
473
481
out = []
474
482
475
- while self .stream.internal_state.state ! = ZSTATE_END :
483
+ while True :
476
484
self .stream.next_out = self .obuf # Reset output buffer.
477
485
self .stream.avail_out = self .obuflen
478
486
err = isal_deflate(& self .stream)
@@ -485,6 +493,10 @@ cdef class Compress:
485
493
# the data is appended to a list.
486
494
# TODO: Improve this with the buffer protocol.
487
495
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
488
500
return b" " .join(out)
489
501
490
502
cdef class Decompress:
0 commit comments