@@ -772,7 +772,6 @@ def __init__(self, file, mode="r", compression=ZIP_STORED, allowZip64=False):
772772 # set the modified flag so central directory gets written
773773 # even if no files are added to the archive
774774 self ._didModify = True
775- self ._start_disk = 0
776775 elif key == 'a' :
777776 try :
778777 # See if file is a zip file
@@ -786,7 +785,6 @@ def __init__(self, file, mode="r", compression=ZIP_STORED, allowZip64=False):
786785 # set the modified flag so central directory gets written
787786 # even if no files are added to the archive
788787 self ._didModify = True
789- self ._start_disk = self .fp .tell ()
790788 else :
791789 raise RuntimeError ('Mode must be "r", "w" or "a"' )
792790 except :
@@ -817,18 +815,17 @@ def _RealGetContents(self):
817815 offset_cd = endrec [_ECD_OFFSET ] # offset of central directory
818816 self ._comment = endrec [_ECD_COMMENT ] # archive comment
819817
820- # self._start_disk: Position of the start of ZIP archive
821- # It is zero, unless ZIP was concatenated to another file
822- self ._start_disk = endrec [_ECD_LOCATION ] - size_cd - offset_cd
818+ # "concat" is zero, unless zip was concatenated to another file
819+ concat = endrec [_ECD_LOCATION ] - size_cd - offset_cd
823820 if endrec [_ECD_SIGNATURE ] == stringEndArchive64 :
824821 # If Zip64 extension structures are present, account for them
825- self . _start_disk -= (sizeEndCentDir64 + sizeEndCentDir64Locator )
822+ concat -= (sizeEndCentDir64 + sizeEndCentDir64Locator )
826823
827824 if self .debug > 2 :
828- inferred = self . _start_disk + offset_cd
829- print "given, inferred, offset" , offset_cd , inferred , self . _start_disk
825+ inferred = concat + offset_cd
826+ print "given, inferred, offset" , offset_cd , inferred , concat
830827 # self.start_dir: Position of start of central directory
831- self .start_dir = offset_cd + self . _start_disk
828+ self .start_dir = offset_cd + concat
832829 fp .seek (self .start_dir , 0 )
833830 data = fp .read (size_cd )
834831 fp = cStringIO .StringIO (data )
@@ -858,7 +855,7 @@ def _RealGetContents(self):
858855 t >> 11 , (t >> 5 )& 0x3F , (t & 0x1F ) * 2 )
859856
860857 x ._decodeExtra ()
861- x .header_offset = x .header_offset + self . _start_disk
858+ x .header_offset = x .header_offset + concat
862859 x .filename = x ._decodeFilename ()
863860 self .filelist .append (x )
864861 self .NameToInfo [x .filename ] = x
@@ -1201,7 +1198,7 @@ def write(self, filename, arcname=None, compress_type=None):
12011198 raise RuntimeError ('Compressed size larger than uncompressed size' )
12021199 # Seek backwards and write file header (which will now include
12031200 # correct CRC and file sizes)
1204- position = self .fp .tell () # Preserve current position in file
1201+ position = self .fp .tell () # Preserve current position in file
12051202 self .fp .seek (zinfo .header_offset , 0 )
12061203 self .fp .write (zinfo .FileHeader (zip64 ))
12071204 self .fp .seek (position , 0 )
@@ -1287,10 +1284,11 @@ def close(self):
12871284 file_size = zinfo .file_size
12881285 compress_size = zinfo .compress_size
12891286
1290- header_offset = zinfo .header_offset - self ._start_disk
1291- if header_offset > ZIP64_LIMIT :
1292- extra .append (header_offset )
1287+ if zinfo .header_offset > ZIP64_LIMIT :
1288+ extra .append (zinfo .header_offset )
12931289 header_offset = 0xffffffffL
1290+ else :
1291+ header_offset = zinfo .header_offset
12941292
12951293 extra_data = zinfo .extra
12961294 if extra :
@@ -1334,7 +1332,7 @@ def close(self):
13341332 # Write end-of-zip-archive record
13351333 centDirCount = len (self .filelist )
13361334 centDirSize = pos2 - pos1
1337- centDirOffset = pos1 - self . _start_disk
1335+ centDirOffset = pos1
13381336 requires_zip64 = None
13391337 if centDirCount > ZIP_FILECOUNT_LIMIT :
13401338 requires_zip64 = "Files count"
0 commit comments