MCPcopy Create free account
hub / github.com/RT-Thread/env-windows / _GzipReader

Class _GzipReader

tools/python-3.11.9-amd64/Lib/gzip.py:455–552  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

453
454
455class _GzipReader(_compression.DecompressReader):
456 def __init__(self, fp):
457 super().__init__(_PaddedFile(fp), zlib.decompressobj,
458 wbits=-zlib.MAX_WBITS)
459 # Set flag indicating start of a new member
460 self._new_member = True
461 self._last_mtime = None
462
463 def _init_read(self):
464 self._crc = zlib.crc32(b"")
465 self._stream_size = 0 # Decompressed size of unconcatenated stream
466
467 def _read_gzip_header(self):
468 last_mtime = _read_gzip_header(self._fp)
469 if last_mtime is None:
470 return False
471 self._last_mtime = last_mtime
472 return True
473
474 def read(self, size=-1):
475 if size < 0:
476 return self.readall()
477 # size=0 is special because decompress(max_length=0) is not supported
478 if not size:
479 return b""
480
481 # For certain input data, a single
482 # call to decompress() may not return
483 # any data. In this case, retry until we get some data or reach EOF.
484 while True:
485 if self._decompressor.eof:
486 # Ending case: we've come to the end of a member in the file,
487 # so finish up this member, and read a new gzip header.
488 # Check the CRC and file size, and set the flag so we read
489 # a new member
490 self._read_eof()
491 self._new_member = True
492 self._decompressor = self._decomp_factory(
493 **self._decomp_args)
494
495 if self._new_member:
496 # If the _new_member flag is set, we have to
497 # jump to the next member, if there is one.
498 self._init_read()
499 if not self._read_gzip_header():
500 self._size = self._pos
501 return b""
502 self._new_member = False
503
504 # Read a chunk of data from the file
505 buf = self._fp.read(io.DEFAULT_BUFFER_SIZE)
506
507 uncompress = self._decompressor.decompress(buf, size)
508 if self._decompressor.unconsumed_tail != b"":
509 self._fp.prepend(self._decompressor.unconsumed_tail)
510 elif self._decompressor.unused_data != b"":
511 # Prepend the already read bytes to the fileobj so they can
512 # be seen by _read_eof() and _read_gzip_header()

Callers 1

__init__Method · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected