@@ -1028,7 +1028,6 @@ def __init__(self, file, mode="r", compression=ZIP_STORED, allowZip64=True):
1028
1028
# set the modified flag so central directory gets written
1029
1029
# even if no files are added to the archive
1030
1030
self ._didModify = True
1031
- self ._start_disk = 0
1032
1031
try :
1033
1032
self .start_dir = self .fp .tell ()
1034
1033
except (AttributeError , OSError ):
@@ -1054,7 +1053,7 @@ def __init__(self, file, mode="r", compression=ZIP_STORED, allowZip64=True):
1054
1053
# set the modified flag so central directory gets written
1055
1054
# even if no files are added to the archive
1056
1055
self ._didModify = True
1057
- self .start_dir = self ._start_disk = self . fp .tell ()
1056
+ self .start_dir = self .fp .tell ()
1058
1057
else :
1059
1058
raise RuntimeError ("Mode must be 'r', 'w', 'x', or 'a'" )
1060
1059
except :
@@ -1098,18 +1097,17 @@ def _RealGetContents(self):
1098
1097
offset_cd = endrec [_ECD_OFFSET ] # offset of central directory
1099
1098
self ._comment = endrec [_ECD_COMMENT ] # archive comment
1100
1099
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
1104
1102
if endrec [_ECD_SIGNATURE ] == stringEndArchive64 :
1105
1103
# If Zip64 extension structures are present, account for them
1106
- self . _start_disk -= (sizeEndCentDir64 + sizeEndCentDir64Locator )
1104
+ concat -= (sizeEndCentDir64 + sizeEndCentDir64Locator )
1107
1105
1108
1106
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 )
1111
1109
# 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
1113
1111
fp .seek (self .start_dir , 0 )
1114
1112
data = fp .read (size_cd )
1115
1113
fp = io .BytesIO (data )
@@ -1149,7 +1147,7 @@ def _RealGetContents(self):
1149
1147
t >> 11 , (t >> 5 )& 0x3F , (t & 0x1F ) * 2 )
1150
1148
1151
1149
x ._decodeExtra ()
1152
- x .header_offset = x .header_offset + self . _start_disk
1150
+ x .header_offset = x .header_offset + concat
1153
1151
self .filelist .append (x )
1154
1152
self .NameToInfo [x .filename ] = x
1155
1153
@@ -1629,10 +1627,11 @@ def _write_end_record(self):
1629
1627
file_size = zinfo .file_size
1630
1628
compress_size = zinfo .compress_size
1631
1629
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 )
1635
1632
header_offset = 0xffffffff
1633
+ else :
1634
+ header_offset = zinfo .header_offset
1636
1635
1637
1636
extra_data = zinfo .extra
1638
1637
min_version = 0
@@ -1679,7 +1678,7 @@ def _write_end_record(self):
1679
1678
# Write end-of-zip-archive record
1680
1679
centDirCount = len (self .filelist )
1681
1680
centDirSize = pos2 - self .start_dir
1682
- centDirOffset = self .start_dir - self . _start_disk
1681
+ centDirOffset = self .start_dir
1683
1682
requires_zip64 = None
1684
1683
if centDirCount > ZIP_FILECOUNT_LIMIT :
1685
1684
requires_zip64 = "Files count"
0 commit comments