Issue #9962: GzipFile now has the peek() method.

This commit is contained in:
Antoine Pitrou 2010-09-29 10:49:46 +00:00
parent 4c2e4fa242
commit c3ed2e7f83
4 changed files with 58 additions and 7 deletions

View file

@ -286,6 +286,28 @@ class TestGzip(unittest.TestCase):
with gzip.GzipFile(fileobj=buf, mode="rb") as f:
self.assertEqual(f.read(), uncompressed)
def test_peek(self):
uncompressed = data1 * 200
with gzip.GzipFile(self.filename, "wb") as f:
f.write(uncompressed)
def sizes():
while True:
for n in range(5, 50, 10):
yield n
with gzip.GzipFile(self.filename, "rb") as f:
f.max_read_chunk = 33
nread = 0
for n in sizes():
s = f.peek(n)
if s == b'':
break
self.assertEqual(f.read(len(s)), s)
nread += len(s)
self.assertEqual(f.read(100), b'')
self.assertEqual(nread, len(uncompressed))
# Testing compress/decompress shortcut functions
def test_compress(self):