mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
Issue #10791: Implement missing method GzipFile.read1(), allowing GzipFile
to be wrapped in a TextIOWrapper. Patch by Nadeem Vawda.
This commit is contained in:
parent
457cdf5e96
commit
4ec4b0c041
3 changed files with 48 additions and 0 deletions
22
Lib/gzip.py
22
Lib/gzip.py
|
@ -348,6 +348,28 @@ class GzipFile(io.BufferedIOBase):
|
|||
self.offset += size
|
||||
return chunk
|
||||
|
||||
def read1(self, size=-1):
|
||||
self._check_closed()
|
||||
if self.mode != READ:
|
||||
import errno
|
||||
raise IOError(errno.EBADF, "read1() on write-only GzipFile object")
|
||||
|
||||
if self.extrasize <= 0 and self.fileobj is None:
|
||||
return b''
|
||||
|
||||
try:
|
||||
self._read()
|
||||
except EOFError:
|
||||
pass
|
||||
if size < 0 or size > self.extrasize:
|
||||
size = self.extrasize
|
||||
|
||||
offset = self.offset - self.extrastart
|
||||
chunk = self.extrabuf[offset: offset + size]
|
||||
self.extrasize -= size
|
||||
self.offset += size
|
||||
return chunk
|
||||
|
||||
def peek(self, n):
|
||||
if self.mode != READ:
|
||||
import errno
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue