[Python-checkins] CVS: python/dist/src/Lib zipfile.py,1.15,1.16
Finn Bock
bckfnn@users.sourceforge.net
Wed, 05 Sep 2001 11:40:35 -0700
Update of /cvsroot/python/python/dist/src/Lib
In directory usw-pr-cvs1:/tmp/cvs-serv10317
Modified Files:
zipfile.py
Log Message:
[ #458701 ] Patch to zipfile.py for Java
Patch by Jim Ahlstrom which lets java's zipfile classes read zipfiles
create by zipfile.py.
Index: zipfile.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/zipfile.py,v
retrieving revision 1.15
retrieving revision 1.16
diff -C2 -d -r1.15 -r1.16
*** zipfile.py 2001/07/19 19:44:25 1.15
--- zipfile.py 2001/09/05 18:40:33 1.16
***************
*** 384,394 ****
self._writecheck(zinfo)
fp = open(filename, "rb")
! zinfo.flag_bits = 0x08
zinfo.header_offset = self.fp.tell() # Start of header bytes
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,
--- 384,395 ----
self._writecheck(zinfo)
fp = open(filename, "rb")
! 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
if zinfo.compress_type == ZIP_DEFLATED:
cmpr = zlib.compressobj(zlib.Z_DEFAULT_COMPRESSION,
***************
*** 416,422 ****
zinfo.CRC = CRC
zinfo.file_size = file_size
! # Write CRC and file sizes after the file data
self.fp.write(struct.pack("<lll", zinfo.CRC, zinfo.compress_size,
zinfo.file_size))
self.filelist.append(zinfo)
self.NameToInfo[zinfo.filename] = zinfo
--- 417,426 ----
zinfo.CRC = CRC
zinfo.file_size = file_size
! # 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