diff options
author | Antoine Pitrou <solipsis@pitrou.net> | 2010-10-04 21:55:14 (GMT) |
---|---|---|
committer | Antoine Pitrou <solipsis@pitrou.net> | 2010-10-04 21:55:14 (GMT) |
commit | 7b998e9f522e088675005eadc4bf934f3d212dc6 (patch) | |
tree | d0247ce95293b26887762fcddfe0f151625cbe11 /Lib/gzip.py | |
parent | 977c707b425ee753d54f3e9010f07ec77ef61274 (diff) | |
download | cpython-7b998e9f522e088675005eadc4bf934f3d212dc6.zip cpython-7b998e9f522e088675005eadc4bf934f3d212dc6.tar.gz cpython-7b998e9f522e088675005eadc4bf934f3d212dc6.tar.bz2 |
GzipFile.peek improvements, suggested by Nir Aides.
Diffstat (limited to 'Lib/gzip.py')
-rw-r--r-- | Lib/gzip.py | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/Lib/gzip.py b/Lib/gzip.py index 58e866b..7c3fd51 100644 --- a/Lib/gzip.py +++ b/Lib/gzip.py @@ -342,16 +342,18 @@ class GzipFile(io.BufferedIOBase): def peek(self, n): if self.mode != READ: import errno - raise IOError(errno.EBADF, "read() on write-only GzipFile object") + raise IOError(errno.EBADF, "peek() on write-only GzipFile object") - # Do not return ridiculously small buffers + # Do not return ridiculously small buffers, for one common idiom + # is to call peek(1) and expect more bytes in return. if n < 100: n = 100 if self.extrasize == 0: if self.fileobj is None: return b'' try: - self._read(max(self.max_read_chunk, n)) + # 1024 is the same buffering heuristic used in read() + self._read(max(n, 1024)) except EOFError: pass offset = self.offset - self.extrastart |