MCPcopy Index your code
hub / github.com/python/cpython / read

Method read

Lib/compression/_common/_streams.py:72–111  ·  view source on GitHub ↗
(self, size=-1)

Source from the content-addressed store, hash-verified

70 return len(data)
71
72 def read(self, size=-1):
73 if size < 0:
74 return self.readall()
75
76 if not size or self._eof:
77 return b""
78 data = None # Default if EOF is encountered
79 # Depending on the input data, our call to the decompressor may not
80 # return any data. In this case, try again after reading another block.
81 while True:
82 if self._decompressor.eof:
83 rawblock = (self._decompressor.unused_data or
84 self._fp.read(BUFFER_SIZE))
85 if not rawblock:
86 break
87 # Continue to next stream.
88 self._decompressor = self._decomp_factory(
89 **self._decomp_args)
90 try:
91 data = self._decompressor.decompress(rawblock, size)
92 except self._trailing_error:
93 # Trailing data isn't a valid compressed stream; ignore it.
94 break
95 else:
96 if self._decompressor.needs_input:
97 rawblock = self._fp.read(BUFFER_SIZE)
98 if not rawblock:
99 raise EOFError("Compressed file ended before the "
100 "end-of-stream marker was reached")
101 else:
102 rawblock = b""
103 data = self._decompressor.decompress(rawblock, size)
104 if data:
105 break
106 if not data:
107 self._eof = True
108 self._size = self._pos
109 return b""
110 self._pos += len(data)
111 return data
112
113 def readall(self):
114 chunks = []

Callers 3

readintoMethod · 0.95
readallMethod · 0.95
seekMethod · 0.95

Calls 2

readallMethod · 0.95
decompressMethod · 0.80

Tested by

no test coverage detected