# HG changeset patch # User Henry S. Thompson # Date 1773657781 0 # Node ID 6b1137bdbd0da42a3632f5c0f4c508bcd183690b # Parent 4497f2ad3a6fd1813273c4bc60a397fe4cf358fb give access to block offsets via callback diff -r 4497f2ad3a6f -r 6b1137bdbd0d lib/python/gzip_plus.py --- a/lib/python/gzip_plus.py Thu Mar 12 18:28:27 2026 +0000 +++ b/lib/python/gzip_plus.py Mon Mar 16 10:43:01 2026 +0000 @@ -180,7 +180,8 @@ myfileobj = None def __init__(self, filename=None, mode=None, - compresslevel=_COMPRESS_LEVEL_BEST, fileobj=None, mtime=None): + compresslevel=_COMPRESS_LEVEL_BEST, fileobj=None, mtime=None, + eob_callback=None): """Constructor for the GzipFile class. At least one of fileobj and filename must be given a @@ -213,6 +214,7 @@ If mtime is omitted or None, the current time is used. Use mtime = 0 to generate a compressed stream that does not depend on creation time. + The optional eobCallback will be called with block boundaries if provided. """ if mode and ('t' in mode or 'U' in mode): @@ -236,7 +238,7 @@ if mode.startswith('r'): self.mode = READ - raw = _GzipReader(fileobj) + raw = _GzipReader(fileobj, eob_callback) self._buffer = io.BufferedReader(raw) self.name = filename @@ -522,7 +524,7 @@ class _GzipReader(_compression.DecompressReader): - def __init__(self, fp): + def __init__(self, fp, eob_callback): super().__init__(_PaddedFile(fp), zlib._ZlibDecompressor, wbits=-zlib.MAX_WBITS) # Set flag indicating start of a new member @@ -530,6 +532,7 @@ self._last_mtime = None self._cur_block = None self._next_block = 0 + self._eob_callback = eob_callback def _init_read(self): self._crc = zlib.crc32(b"") @@ -618,6 +621,8 @@ self._cur_block = self._next_block self._next_block = self._fp.tell() + if self._eob_callback is not None: + self._eob_callback(self._cur_block, self._next_block) def _rewind(self): super()._rewind()