From fb0ea525d528153838586bf8ece15a45bbf5ddf3 Mon Sep 17 00:00:00 2001 From: Tim Peters Date: Mon, 4 Nov 2002 19:50:11 +0000 Subject: Related to SF patch 618135: gzip.py and files > 2G. Fixed the signed/unsigned confusions when dealing with files >= 2GB. 4GB is still a hard limitation of the gzip file format, though. Testing this was a bitch on Win98SE due to frequent system freezes. It didn't freeze while running gzip, it kept freezing while trying to *create* a > 2GB test file! This wasn't Python's doing. I don't know of a reasonable way to test this functionality in regrtest.py, so I'm not checking in a test case (a test case would necessarily require creating a 2GB+ file first, using gzip to zip it, using gzip to unzip it again, and then compare before-and-after; so >4GB free space would be required, and a loooong time; I did all this "by hand" once). Bugfix candidate, I guess. --- Lib/gzip.py | 52 ++++++++++++++++++++++++++++++++++------------------ Misc/NEWS | 6 +++++- 2 files changed, 39 insertions(+), 19 deletions(-) diff --git a/Lib/gzip.py b/Lib/gzip.py index 55d448d..8802adb 100644 --- a/Lib/gzip.py +++ b/Lib/gzip.py @@ -15,12 +15,21 @@ FTEXT, FHCRC, FEXTRA, FNAME, FCOMMENT = 1, 2, 4, 8, 16 READ, WRITE = 1, 2 +def U32(i): + """Return i as an unsigned integer, assuming it fits in 32 bits. + + If it's >= 2GB when viewed as a 32-bit unsigned int, return a long. + """ + if i < 0: + i += 1L << 32 + return i + def write32(output, value): output.write(struct.pack(" 0: line = self.readline() - if line == "": break + if line == "": + break L.append(line) sizehint = sizehint - len(line) diff --git a/Misc/NEWS b/Misc/NEWS index c8334d7..980e4d2 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -355,6 +355,10 @@ Extension modules Library ------- +- gzip.py now handles files exceeding 2GB. Note that 4GB is still a + fundamental limitation of the underlying gzip file format (it only + has 32 bits to record the file size). + - xml.sax.saxutils.unescape has been added, to replace entity references with their entity value. @@ -365,7 +369,7 @@ Library - Various configure methods of Tkinter have been stream-lined, so that tag_configure, image_configure, window_configure now return a - dictionary when invoked with no argument. + dictionary when invoked with no argument. - Importing the readline module now no longer has the side effect of calling setlocale(LC_CTYPE, ""). The initial "C" locale, or -- cgit v0.12