MCPcopy Index your code
hub / github.com/RustPython/RustPython / _GzipReader

Class _GzipReader

Lib/gzip.py:526–621  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

524
525
526class _GzipReader(_streams.DecompressReader):
527 def __init__(self, fp):
528 super().__init__(_PaddedFile(fp), zlib._ZlibDecompressor,
529 wbits=-zlib.MAX_WBITS)
530 # Set flag indicating start of a new member
531 self._new_member = True
532 self._last_mtime = None
533
534 def _init_read(self):
535 self._crc = zlib.crc32(b"")
536 self._stream_size = 0 # Decompressed size of unconcatenated stream
537
538 def _read_gzip_header(self):
539 last_mtime = _read_gzip_header(self._fp)
540 if last_mtime is None:
541 return False
542 self._last_mtime = last_mtime
543 return True
544
545 def read(self, size=-1):
546 if size < 0:
547 return self.readall()
548 # size=0 is special because decompress(max_length=0) is not supported
549 if not size:
550 return b""
551
552 # For certain input data, a single
553 # call to decompress() may not return
554 # any data. In this case, retry until we get some data or reach EOF.
555 while True:
556 if self._decompressor.eof:
557 # Ending case: we've come to the end of a member in the file,
558 # so finish up this member, and read a new gzip header.
559 # Check the CRC and file size, and set the flag so we read
560 # a new member
561 self._read_eof()
562 self._new_member = True
563 self._decompressor = self._decomp_factory(
564 **self._decomp_args)
565
566 if self._new_member:
567 # If the _new_member flag is set, we have to
568 # jump to the next member, if there is one.
569 self._init_read()
570 if not self._read_gzip_header():
571 self._size = self._pos
572 return b""
573 self._new_member = False
574
575 # Read a chunk of data from the file
576 if self._decompressor.needs_input:
577 buf = self._fp.read(READ_BUFFER_SIZE)
578 uncompress = self._decompressor.decompress(buf, size)
579 else:
580 uncompress = self._decompressor.decompress(b"", size)
581
582 if self._decompressor.unused_data != b"":
583 # Prepend the already read bytes to the fileobj so they can

Callers 1

__init__Method · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected