diff -r 8c8315bac6a8 Lib/gzip.py --- a/Lib/gzip.py Sun Apr 20 09:45:00 2014 -0700 +++ b/Lib/gzip.py Sun Apr 20 19:06:28 2014 -0500 @@ -16,6 +16,8 @@ READ, WRITE = 1, 2 +_CHUNK_SIZE = 16 * 1024 + def open(filename, mode="rb", compresslevel=9, encoding=None, errors=None, newline=None): """Open a gzip-compressed file in binary or text mode. @@ -355,7 +357,7 @@ if self.extrasize <= 0 and self.fileobj is None: return b'' - readsize = 1024 + readsize = _CHUNK_SIZE if size < 0: # get the whole thing while self._read(readsize): readsize = min(self.max_read_chunk, readsize * 2) @@ -410,8 +412,8 @@ if self.fileobj is None: return b'' # Ensure that we don't return b"" if we haven't reached EOF. - # 1024 is the same buffering heuristic used in read() - while self.extrasize == 0 and self._read(max(n, 1024)): + # _CHUNK_SIZE is the same buffering heuristic used in read() + while self.extrasize == 0 and self._read(max(n, _CHUNK_SIZE)): pass offset = self.offset - self.extrastart remaining = self.extrasize @@ -422,7 +424,7 @@ self.extrasize = len(buf) + self.extrasize self.offset -= len(buf) - def _read(self, size=1024): + def _read(self, size=_CHUNK_SIZE): if self.fileobj is None: return False @@ -560,18 +562,18 @@ if offset < self.offset: raise OSError('Negative seek in write mode') count = offset - self.offset - chunk = bytes(1024) - for i in range(count // 1024): + chunk = bytes(_CHUNK_SIZE) + for i in range(count // _CHUNK_SIZE): self.write(chunk) - self.write(bytes(count % 1024)) + self.write(bytes(count % _CHUNK_SIZE)) elif self.mode == READ: if offset < self.offset: # for negative seek, rewind and do positive seek self.rewind() count = offset - self.offset - for i in range(count // 1024): - self.read(1024) - self.read(count % 1024) + for i in range(count // _CHUNK_SIZE): + self.read(_CHUNK_SIZE) + self.read(count % _CHUNK_SIZE) return self.offset