Issue #2846: Add support for gzip.GzipFile reading zero-padded files.

Patch by Brian Curtin.
This commit is contained in:
Antoine Pitrou 2010-01-13 14:32:10 +00:00
parent 10042922d9
commit 5a9112c0cc
4 changed files with 27 additions and 0 deletions

View file

@ -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