Issue #1675951: Allow GzipFile to work with unseekable file objects.
Patch by Florian Festi.
diff --git a/Lib/test/test_gzip.py b/Lib/test/test_gzip.py
index a95af05..e49fe00 100644
--- a/Lib/test/test_gzip.py
+++ b/Lib/test/test_gzip.py
@@ -22,6 +22,17 @@
"""
+class UnseekableIO(io.BytesIO):
+ def seekable(self):
+ return False
+
+ def tell(self):
+ raise io.UnsupportedOperation
+
+ def seek(self, *args):
+ raise io.UnsupportedOperation
+
+
class TestGzip(unittest.TestCase):
filename = support.TESTFN
@@ -265,6 +276,16 @@
d = f.read()
self.assertEqual(d, data1 * 50, "Incorrect data in file")
+ def test_non_seekable_file(self):
+ uncompressed = data1 * 50
+ buf = UnseekableIO()
+ with gzip.GzipFile(fileobj=buf, mode="wb") as f:
+ f.write(uncompressed)
+ compressed = buf.getvalue()
+ buf = UnseekableIO(compressed)
+ with gzip.GzipFile(fileobj=buf, mode="rb") as f:
+ self.assertEqual(f.read(), uncompressed)
+
# Testing compress/decompress shortcut functions
def test_compress(self):