Issue #9962: GzipFile now has the peek() method.
diff --git a/Lib/test/test_gzip.py b/Lib/test/test_gzip.py
index e49fe00..8e493b5 100644
--- a/Lib/test/test_gzip.py
+++ b/Lib/test/test_gzip.py
@@ -286,6 +286,28 @@
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):