Mercurial > hg > cc > cirrus_work
changeset 353:6b1137bdbd0d trim
give access to block offsets via callback
| author | Henry S. Thompson <ht@inf.ed.ac.uk> |
|---|---|
| date | Mon, 16 Mar 2026 10:43:01 +0000 |
| parents | 4497f2ad3a6f |
| children | 90f541382b0e |
| files | lib/python/gzip_plus.py |
| diffstat | 1 files changed, 8 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- 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()
