MCPcopy Index your code
hub / github.com/RustPython/RustPython / _create_header

Method _create_header

Lib/tarfile.py:1159–1198  ·  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

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