summaryrefslogtreecommitdiffstats
path: root/Lib/gzip.py
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2010-01-13 14:32:10 (GMT)
committerAntoine Pitrou <solipsis@pitrou.net>2010-01-13 14:32:10 (GMT)
commit5a9112c0cc33614c284c18a6f622a32c97b7ae3d (patch)
tree99f33d8df4116a351e721dd0abfc10f07b9e6330 /Lib/gzip.py
parent10042922d9dbb25c6e8b63698c34b6f3943a8cf1 (diff)
downloadcpython-5a9112c0cc33614c284c18a6f622a32c97b7ae3d.zip
cpython-5a9112c0cc33614c284c18a6f622a32c97b7ae3d.tar.gz
cpython-5a9112c0cc33614c284c18a6f622a32c97b7ae3d.tar.bz2
Issue #2846: Add support for gzip.GzipFile reading zero-padded files.
Patch by Brian Curtin.
Diffstat (limited to 'Lib/gzip.py')
-rw-r--r--Lib/gzip.py9
1 files changed, 9 insertions, 0 deletions
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 @@ class GzipFile(io.BufferedIOBase):
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