Issue #2846: Add support for gzip.GzipFile reading zero-padded files.
Patch by Brian Curtin.
diff --git a/Lib/gzip.py b/Lib/gzip.py
index 26f4354..13f2ca2 100644
--- a/Lib/gzip.py
+++ b/Lib/gzip.py
@@ -330,6 +330,15 @@
elif isize != (self.size & 0xffffffffL):
raise IOError, "Incorrect length of data produced"
+ # Gzip files can be padded with zeroes and still have archives.
+ # Consume all zero bytes and set the file position to the first
+ # non-zero byte. See http://www.gzip.org/#faq8
+ c = "\x00"
+ while c == "\x00":
+ c = self.fileobj.read(1)
+ if c:
+ self.fileobj.seek(-1, 1)
+
@property
def closed(self):
return self.fileobj is None