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

Method _create_header

Lib/tarfile.py:1157–1196  ·  view source on GitHub ↗

Return a header block. info is a dictionary with file information, format must be one of the *_FORMAT constants.

(info, format, encoding, errors)

Source from the content-addressed store, hash-verified

1155
1156 @staticmethod
1157 def _create_header(info, format, encoding, errors):
1158 """Return a header block. info is a dictionary with file
1159 information, format must be one of the *_FORMAT constants.
1160 """
1161 has_device_fields = info.get("type") in (CHRTYPE, BLKTYPE)
1162 if has_device_fields:
1163 devmajor = itn(info.get("devmajor", 0), 8, format)
1164 devminor = itn(info.get("devminor", 0), 8, format)
1165 else:
1166 devmajor = stn("", 8, encoding, errors)
1167 devminor = stn("", 8, encoding, errors)
1168
1169 # None values in metadata should cause ValueError.
1170 # itn()/stn() do this for all fields except type.
1171 filetype = info.get("type", REGTYPE)
1172 if filetype is None:
1173 raise ValueError("TarInfo.type must not be None")
1174
1175 parts = [
1176 stn(info.get("name", ""), 100, encoding, errors),
1177 itn(info.get("mode", 0) & 0o7777, 8, format),
1178 itn(info.get("uid", 0), 8, format),
1179 itn(info.get("gid", 0), 8, format),
1180 itn(info.get("size", 0), 12, format),
1181 itn(info.get("mtime", 0), 12, format),
1182 b" ", # checksum field
1183 filetype,
1184 stn(info.get("linkname", ""), 100, encoding, errors),
1185 info.get("magic", POSIX_MAGIC),
1186 stn(info.get("uname", ""), 32, encoding, errors),
1187 stn(info.get("gname", ""), 32, encoding, errors),
1188 devmajor,
1189 devminor,
1190 stn(info.get("prefix", ""), 155, encoding, errors)
1191 ]
1192
1193 buf = struct.pack("%ds" % BLOCKSIZE, b"".join(parts))
1194 chksum = calc_chksums(buf[-BLOCKSIZE:])[0]
1195 buf = buf[:-364] + bytes("%06o\0" % chksum, "ascii") + buf[-357:]
1196 return buf
1197
1198 @staticmethod
1199 def _create_payload(payload):

Callers 5

create_ustar_headerMethod · 0.95
create_gnu_headerMethod · 0.95
create_pax_headerMethod · 0.95

Calls 6

itnFunction · 0.85
stnFunction · 0.85
calc_chksumsFunction · 0.85
getMethod · 0.45
packMethod · 0.45
joinMethod · 0.45

Tested by

no test coverage detected