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

Method read

Lib/gzip.py:545–596  ·  view source on GitHub ↗
(self, size=-1)

Source from the content-addressed store, hash-verified

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
584 # be seen by _read_eof() and _read_gzip_header()
585 self._fp.prepend(self._decompressor.unused_data)
586
587 if uncompress != b"":
588 break
589 if buf == b"":
590 raise EOFError("Compressed file ended before the "
591 "end-of-stream marker was reached")
592
593 self._crc = zlib.crc32(uncompress, self._crc)
594 self._stream_size += len(uncompress)
595 self._pos += len(uncompress)
596 return uncompress
597
598 def _read_eof(self):
599 # We've read to the end of the file

Callers

nothing calls this directly

Calls 8

_read_eofMethod · 0.95
_init_readMethod · 0.95
_read_gzip_headerMethod · 0.95
lenFunction · 0.85
prependMethod · 0.80
readallMethod · 0.45
readMethod · 0.45
decompressMethod · 0.45

Tested by

no test coverage detected