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

Method read

tools/python-3.11.9-amd64/Lib/gzip.py:474–523  ·  view source on GitHub ↗
(self, size=-1)

Source from the content-addressed store, hash-verified

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()
513 self._fp.prepend(self._decompressor.unused_data)
514
515 if uncompress != b"":
516 break
517 if buf == b"":
518 raise EOFError("Compressed file ended before the "
519 "end-of-stream marker was reached")
520
521 self._add_read_data( uncompress )
522 self._pos += len(uncompress)
523 return uncompress
524
525 def _add_read_data(self, data):
526 self._crc = zlib.crc32(data, self._crc)

Callers

nothing calls this directly

Calls 8

_read_eofMethod · 0.95
_init_readMethod · 0.95
_read_gzip_headerMethod · 0.95
_add_read_dataMethod · 0.95
readallMethod · 0.45
readMethod · 0.45
decompressMethod · 0.45
prependMethod · 0.45

Tested by

no test coverage detected