Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 8e33fd7

Browse files
committed
Merged revisions 77472-77473 via svnmerge from
svn+ssh://[email protected]/python/trunk ........ r77472 | antoine.pitrou | 2010-01-13 15:32:10 +0100 (mer., 13 janv. 2010) | 5 lines Issue #2846: Add support for gzip.GzipFile reading zero-padded files. Patch by Brian Curtin. ........ r77473 | antoine.pitrou | 2010-01-13 15:32:51 +0100 (mer., 13 janv. 2010) | 3 lines Add ACKS entry for r77472. ........
1 parent f068f94 commit 8e33fd7

5 files changed

Lines changed: 28 additions & 0 deletions

File tree

Doc/library/gzip.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@ The module defines the following items:
7272
.. versionchanged:: 3.1
7373
Support for the :keyword:`with` statement was added.
7474

75+
.. versionchanged:: 3.2
76+
Support for zero-padded files was added.
77+
7578

7679
.. function:: open(filename, mode='rb', compresslevel=9)
7780

Lib/gzip.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,15 @@ def _read_eof(self):
348348
elif isize != (self.size & 0xffffffff):
349349
raise IOError("Incorrect length of data produced")
350350

351+
# Gzip files can be padded with zeroes and still have archives.
352+
# Consume all zero bytes and set the file position to the first
353+
# non-zero byte. See http://www.gzip.org/#faq8
354+
c = b"\x00"
355+
while c == b"\x00":
356+
c = self.fileobj.read(1)
357+
if c:
358+
self.fileobj.seek(-1, 1)
359+
351360
@property
352361
def closed(self):
353362
return self.fileobj is None

Lib/test/test_gzip.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,18 @@ def test_with_open(self):
253253
else:
254254
self.fail("1/0 didn't raise an exception")
255255

256+
def test_zero_padded_file(self):
257+
with gzip.GzipFile(self.filename, "wb") as f:
258+
f.write(data1 * 50)
259+
260+
# Pad the file with zeroes
261+
with open(self.filename, "ab") as f:
262+
f.write(b"\x00" * 50)
263+
264+
with gzip.GzipFile(self.filename, "rb") as f:
265+
d = f.read()
266+
self.assertEqual(d, data1 * 50, "Incorrect data in file")
267+
256268
def test_main(verbose=None):
257269
support.run_unittest(TestGzip)
258270

Misc/ACKS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ Simon Cross
164164
Drew Csillag
165165
John Cugini
166166
Tom Culliton
167+
Brian Curtin
167168
Lisandro Dalcin
168169
Andrew Dalke
169170
Lars Damerow

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,9 @@ C-API
213213
Library
214214
-------
215215

216+
- Issue #2846: Add support for gzip.GzipFile reading zero-padded files.
217+
Patch by Brian Curtin.
218+
216219
- Issue #7681: Use floor division in appropiate places in the wave module.
217220

218221
- Issue #5372: Drop the reuse of .o files in Distutils' ccompiler (since

0 commit comments

Comments
 (0)