@@ -1028,7 +1028,6 @@ def __init__(self, file, mode="r", compression=ZIP_STORED, allowZip64=True):
10281028 # set the modified flag so central directory gets written
10291029 # even if no files are added to the archive
10301030 self ._didModify = True
1031- self ._start_disk = 0
10321031 try :
10331032 self .start_dir = self .fp .tell ()
10341033 except (AttributeError , OSError ):
@@ -1054,7 +1053,7 @@ def __init__(self, file, mode="r", compression=ZIP_STORED, allowZip64=True):
10541053 # set the modified flag so central directory gets written
10551054 # even if no files are added to the archive
10561055 self ._didModify = True
1057- self .start_dir = self ._start_disk = self . fp .tell ()
1056+ self .start_dir = self .fp .tell ()
10581057 else :
10591058 raise RuntimeError ("Mode must be 'r', 'w', 'x', or 'a'" )
10601059 except :
@@ -1098,18 +1097,17 @@ def _RealGetContents(self):
10981097 offset_cd = endrec [_ECD_OFFSET ] # offset of central directory
10991098 self ._comment = endrec [_ECD_COMMENT ] # archive comment
11001099
1101- # self._start_disk: Position of the start of ZIP archive
1102- # It is zero, unless ZIP was concatenated to another file
1103- self ._start_disk = endrec [_ECD_LOCATION ] - size_cd - offset_cd
1100+ # "concat" is zero, unless zip was concatenated to another file
1101+ concat = endrec [_ECD_LOCATION ] - size_cd - offset_cd
11041102 if endrec [_ECD_SIGNATURE ] == stringEndArchive64 :
11051103 # If Zip64 extension structures are present, account for them
1106- self . _start_disk -= (sizeEndCentDir64 + sizeEndCentDir64Locator )
1104+ concat -= (sizeEndCentDir64 + sizeEndCentDir64Locator )
11071105
11081106 if self .debug > 2 :
1109- inferred = self . _start_disk + offset_cd
1110- print ("given, inferred, offset" , offset_cd , inferred , self . _start_disk )
1107+ inferred = concat + offset_cd
1108+ print ("given, inferred, offset" , offset_cd , inferred , concat )
11111109 # self.start_dir: Position of start of central directory
1112- self .start_dir = offset_cd + self . _start_disk
1110+ self .start_dir = offset_cd + concat
11131111 fp .seek (self .start_dir , 0 )
11141112 data = fp .read (size_cd )
11151113 fp = io .BytesIO (data )
@@ -1149,7 +1147,7 @@ def _RealGetContents(self):
11491147 t >> 11 , (t >> 5 )& 0x3F , (t & 0x1F ) * 2 )
11501148
11511149 x ._decodeExtra ()
1152- x .header_offset = x .header_offset + self . _start_disk
1150+ x .header_offset = x .header_offset + concat
11531151 self .filelist .append (x )
11541152 self .NameToInfo [x .filename ] = x
11551153
@@ -1629,10 +1627,11 @@ def _write_end_record(self):
16291627 file_size = zinfo .file_size
16301628 compress_size = zinfo .compress_size
16311629
1632- header_offset = zinfo .header_offset - self ._start_disk
1633- if header_offset > ZIP64_LIMIT :
1634- extra .append (header_offset )
1630+ if zinfo .header_offset > ZIP64_LIMIT :
1631+ extra .append (zinfo .header_offset )
16351632 header_offset = 0xffffffff
1633+ else :
1634+ header_offset = zinfo .header_offset
16361635
16371636 extra_data = zinfo .extra
16381637 min_version = 0
@@ -1679,7 +1678,7 @@ def _write_end_record(self):
16791678 # Write end-of-zip-archive record
16801679 centDirCount = len (self .filelist )
16811680 centDirSize = pos2 - self .start_dir
1682- centDirOffset = self .start_dir - self . _start_disk
1681+ centDirOffset = self .start_dir
16831682 requires_zip64 = None
16841683 if centDirCount > ZIP_FILECOUNT_LIMIT :
16851684 requires_zip64 = "Files count"
0 commit comments