diff options
author | Finn Bock <bckfnn@worldonline.dk> | 2001-09-05 18:40:33 (GMT) |
---|---|---|
committer | Finn Bock <bckfnn@worldonline.dk> | 2001-09-05 18:40:33 (GMT) |
commit | 03a3bb812a002119f139c57b902172ed6499c28d (patch) | |
tree | db60ee0cfc4ebb2c2b8b1e63fe57458cde05377e /Lib/zipfile.py | |
parent | 198c1d8b5981e8e58a229827ac5c344fcd004b54 (diff) | |
download | cpython-03a3bb812a002119f139c57b902172ed6499c28d.zip cpython-03a3bb812a002119f139c57b902172ed6499c28d.tar.gz cpython-03a3bb812a002119f139c57b902172ed6499c28d.tar.bz2 |
[ #458701 ] Patch to zipfile.py for Java
Patch by Jim Ahlstrom which lets java's zipfile classes read zipfiles
create by zipfile.py.
Diffstat (limited to 'Lib/zipfile.py')
-rw-r--r-- | Lib/zipfile.py | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/Lib/zipfile.py b/Lib/zipfile.py index bd9df9b..0c63b91 100644 --- a/Lib/zipfile.py +++ b/Lib/zipfile.py @@ -383,13 +383,14 @@ class ZipFile: zinfo.compress_type = compress_type self._writecheck(zinfo) fp = open(filename, "rb") - zinfo.flag_bits = 0x08 + zinfo.flag_bits = 0x00 zinfo.header_offset = self.fp.tell() # Start of header bytes + # Must overwrite CRC and sizes with correct data later + zinfo.CRC = CRC = 0 + zinfo.compress_size = compress_size = 0 + zinfo.file_size = file_size = 0 self.fp.write(zinfo.FileHeader()) zinfo.file_offset = self.fp.tell() # Start of file bytes - CRC = 0 - compress_size = 0 - file_size = 0 if zinfo.compress_type == ZIP_DEFLATED: cmpr = zlib.compressobj(zlib.Z_DEFAULT_COMPRESSION, zlib.DEFLATED, -15) @@ -415,9 +416,12 @@ class ZipFile: zinfo.compress_size = file_size zinfo.CRC = CRC zinfo.file_size = file_size - # Write CRC and file sizes after the file data + # Seek backwards and write CRC and file sizes + position = self.fp.tell() # Preserve current position in file + self.fp.seek(zinfo.header_offset + 14, 0) self.fp.write(struct.pack("<lll", zinfo.CRC, zinfo.compress_size, zinfo.file_size)) + self.fp.seek(position, 0) self.filelist.append(zinfo) self.NameToInfo[zinfo.filename] = zinfo |