MCPcopy Index your code
hub / github.com/python/cpython / _write_end_record

Method _write_end_record

Lib/zipfile/__init__.py:2083–2177  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

2081 self._fpclose(fp)
2082
2083 def _write_end_record(self):
2084 for zinfo in self.filelist: # write central directory
2085 dt = zinfo.date_time
2086 dosdate = (dt[0] - 1980) << 9 | dt[1] << 5 | dt[2]
2087 dostime = dt[3] << 11 | dt[4] << 5 | (dt[5] // 2)
2088 extra = []
2089 if zinfo.file_size > ZIP64_LIMIT \
2090 or zinfo.compress_size > ZIP64_LIMIT:
2091 extra.append(zinfo.file_size)
2092 extra.append(zinfo.compress_size)
2093 file_size = 0xffffffff
2094 compress_size = 0xffffffff
2095 else:
2096 file_size = zinfo.file_size
2097 compress_size = zinfo.compress_size
2098
2099 if zinfo.header_offset > ZIP64_LIMIT:
2100 extra.append(zinfo.header_offset)
2101 header_offset = 0xffffffff
2102 else:
2103 header_offset = zinfo.header_offset
2104
2105 extra_data = zinfo.extra
2106 min_version = 0
2107 if extra:
2108 # Append a ZIP64 field to the extra's
2109 extra_data = _Extra.strip(extra_data, (1,))
2110 extra_data = struct.pack(
2111 '<HH' + 'Q'*len(extra),
2112 1, 8*len(extra), *extra) + extra_data
2113
2114 min_version = ZIP64_VERSION
2115
2116 if zinfo.compress_type == ZIP_BZIP2:
2117 min_version = max(BZIP2_VERSION, min_version)
2118 elif zinfo.compress_type == ZIP_LZMA:
2119 min_version = max(LZMA_VERSION, min_version)
2120 elif zinfo.compress_type == ZIP_ZSTANDARD:
2121 min_version = max(ZSTANDARD_VERSION, min_version)
2122
2123 extract_version = max(min_version, zinfo.extract_version)
2124 create_version = max(min_version, zinfo.create_version)
2125 filename, flag_bits = zinfo._encodeFilenameFlags()
2126 centdir = struct.pack(structCentralDir,
2127 stringCentralDir, create_version,
2128 zinfo.create_system, extract_version, zinfo.reserved,
2129 flag_bits, zinfo.compress_type, dostime, dosdate,
2130 zinfo.CRC, compress_size, file_size,
2131 len(filename), len(extra_data), len(zinfo.comment),
2132 0, zinfo.internal_attr, zinfo.external_attr,
2133 header_offset)
2134 self.fp.write(centdir)
2135 self.fp.write(filename)
2136 self.fp.write(extra_data)
2137 self.fp.write(zinfo.comment)
2138
2139 pos2 = self.fp.tell()
2140 # Write end-of-zip-archive record

Callers 1

closeMethod · 0.95

Calls 9

LargeZipFileClass · 0.85
_encodeFilenameFlagsMethod · 0.80
appendMethod · 0.45
stripMethod · 0.45
packMethod · 0.45
writeMethod · 0.45
tellMethod · 0.45
truncateMethod · 0.45
flushMethod · 0.45

Tested by

no test coverage detected