@@ -1109,7 +1109,6 @@ def __init__(self, file, mode="r", compression=ZIP_STORED, allowZip64=True):
11091109 # set the modified flag so central directory gets written
11101110 # even if no files are added to the archive
11111111 self ._didModify = True
1112- self ._start_disk = 0
11131112 try :
11141113 self .start_dir = self .fp .tell ()
11151114 except (AttributeError , OSError ):
@@ -1135,7 +1134,7 @@ def __init__(self, file, mode="r", compression=ZIP_STORED, allowZip64=True):
11351134 # set the modified flag so central directory gets written
11361135 # even if no files are added to the archive
11371136 self ._didModify = True
1138- self .start_dir = self ._start_disk = self . fp .tell ()
1137+ self .start_dir = self .fp .tell ()
11391138 else :
11401139 raise ValueError ("Mode must be 'r', 'w', 'x', or 'a'" )
11411140 except :
@@ -1179,18 +1178,17 @@ def _RealGetContents(self):
11791178 offset_cd = endrec [_ECD_OFFSET ] # offset of central directory
11801179 self ._comment = endrec [_ECD_COMMENT ] # archive comment
11811180
1182- # self._start_disk: Position of the start of ZIP archive
1183- # It is zero, unless ZIP was concatenated to another file
1184- self ._start_disk = endrec [_ECD_LOCATION ] - size_cd - offset_cd
1181+ # "concat" is zero, unless zip was concatenated to another file
1182+ concat = endrec [_ECD_LOCATION ] - size_cd - offset_cd
11851183 if endrec [_ECD_SIGNATURE ] == stringEndArchive64 :
11861184 # If Zip64 extension structures are present, account for them
1187- self . _start_disk -= (sizeEndCentDir64 + sizeEndCentDir64Locator )
1185+ concat -= (sizeEndCentDir64 + sizeEndCentDir64Locator )
11881186
11891187 if self .debug > 2 :
1190- inferred = self . _start_disk + offset_cd
1191- print ("given, inferred, offset" , offset_cd , inferred , self . _start_disk )
1188+ inferred = concat + offset_cd
1189+ print ("given, inferred, offset" , offset_cd , inferred , concat )
11921190 # self.start_dir: Position of start of central directory
1193- self .start_dir = offset_cd + self . _start_disk
1191+ self .start_dir = offset_cd + concat
11941192 fp .seek (self .start_dir , 0 )
11951193 data = fp .read (size_cd )
11961194 fp = io .BytesIO (data )
@@ -1230,7 +1228,7 @@ def _RealGetContents(self):
12301228 t >> 11 , (t >> 5 )& 0x3F , (t & 0x1F ) * 2 )
12311229
12321230 x ._decodeExtra ()
1233- x .header_offset = x .header_offset + self . _start_disk
1231+ x .header_offset = x .header_offset + concat
12341232 self .filelist .append (x )
12351233 self .NameToInfo [x .filename ] = x
12361234
@@ -1701,10 +1699,11 @@ def _write_end_record(self):
17011699 file_size = zinfo .file_size
17021700 compress_size = zinfo .compress_size
17031701
1704- header_offset = zinfo .header_offset - self ._start_disk
1705- if header_offset > ZIP64_LIMIT :
1706- extra .append (header_offset )
1702+ if zinfo .header_offset > ZIP64_LIMIT :
1703+ extra .append (zinfo .header_offset )
17071704 header_offset = 0xffffffff
1705+ else :
1706+ header_offset = zinfo .header_offset
17081707
17091708 extra_data = zinfo .extra
17101709 min_version = 0
@@ -1751,7 +1750,7 @@ def _write_end_record(self):
17511750 # Write end-of-zip-archive record
17521751 centDirCount = len (self .filelist )
17531752 centDirSize = pos2 - self .start_dir
1754- centDirOffset = self .start_dir - self . _start_disk
1753+ centDirOffset = self .start_dir
17551754 requires_zip64 = None
17561755 if centDirCount > ZIP_FILECOUNT_LIMIT :
17571756 requires_zip64 = "Files count"
0 commit comments