Skip to content

Commit 175df5b

Browse files
committed
Fix flushing behavior for gzip_ng_threaded
1 parent 454a452 commit 175df5b

File tree

2 files changed

+10
-11
lines changed

2 files changed

+10
-11
lines changed

CHANGELOG.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ version develop
1111
-----------------
1212
+ Python 3.14 is supported.
1313
+ Python 3.8 and 3.9 are no longer supported.
14+
+ Fix an issue where flushing using igzip_threaded caused a gzip end of stream
15+
and started a new gzip stream. In essence creating a concatenated gzip
16+
stream. Now it is in concordance with how single threaded gzip streams
17+
are flushed using Z_SYNC_FLUSH.
1418
+ Switched to setuptools-scm for building the package rather than versioningit.
1519
+ Test files are added to the source distribution.
1620

src/zlib_ng/gzip_ng_threaded.py

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -321,30 +321,25 @@ def write(self, b) -> int:
321321
self.input_queues[worker_index].put((data, zdict))
322322
return len(data)
323323

324-
def _end_gzip_stream(self):
324+
def flush(self):
325325
self._check_closed()
326326
# Wait for all data to be compressed
327327
for in_q in self.input_queues:
328328
in_q.join()
329329
# Wait for all data to be written
330330
for out_q in self.output_queues:
331331
out_q.join()
332-
# Write an empty deflate block with a lost block marker.
332+
self.raw.flush()
333+
334+
def close(self):
335+
if self._closed:
336+
return
333337
self.raw.write(zlib_ng.compress(b"", wbits=-15))
334338
trailer = struct.pack("<II", self._crc, self._size & 0xFFFFFFFF)
335339
self.raw.write(trailer)
336340
self._crc = 0
337341
self._size = 0
338342
self.raw.flush()
339-
340-
def flush(self):
341-
self._end_gzip_stream()
342-
self._write_gzip_header()
343-
344-
def close(self) -> None:
345-
if self._closed:
346-
return
347-
self._end_gzip_stream()
348343
self.stop()
349344
if self.exception:
350345
self.raw.close()

0 commit comments

Comments
 (0)