mirror of
https://github.com/python/cpython.git
synced 2025-08-30 21:48:47 +00:00
Issue #9962: GzipFile now has the peek() method.
This commit is contained in:
parent
4c2e4fa242
commit
c3ed2e7f83
4 changed files with 58 additions and 7 deletions
|
@ -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):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue