MCPcopy Create free account
hub / github.com/RT-Thread/env-windows / _create_header

Method _create_header

tools/python-3.11.9-amd64/Lib/tarfile.py:1106–1145  ·  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

1104
1105 @staticmethod
1106 def _create_header(info, format, encoding, errors):
1107 """Return a header block. info is a dictionary with file
1108 information, format must be one of the *_FORMAT constants.
1109 """
1110 has_device_fields = info.get("type") in (CHRTYPE, BLKTYPE)
1111 if has_device_fields:
1112 devmajor = itn(info.get("devmajor", 0), 8, format)
1113 devminor = itn(info.get("devminor", 0), 8, format)
1114 else:
1115 devmajor = stn("", 8, encoding, errors)
1116 devminor = stn("", 8, encoding, errors)
1117
1118 # None values in metadata should cause ValueError.
1119 # itn()/stn() do this for all fields except type.
1120 filetype = info.get("type", REGTYPE)
1121 if filetype is None:
1122 raise ValueError("TarInfo.type must not be None")
1123
1124 parts = [
1125 stn(info.get("name", ""), 100, encoding, errors),
1126 itn(info.get("mode", 0) & 0o7777, 8, format),
1127 itn(info.get("uid", 0), 8, format),
1128 itn(info.get("gid", 0), 8, format),
1129 itn(info.get("size", 0), 12, format),
1130 itn(info.get("mtime", 0), 12, format),
1131 b" ", # checksum field
1132 filetype,
1133 stn(info.get("linkname", ""), 100, encoding, errors),
1134 info.get("magic", POSIX_MAGIC),
1135 stn(info.get("uname", ""), 32, encoding, errors),
1136 stn(info.get("gname", ""), 32, encoding, errors),
1137 devmajor,
1138 devminor,
1139 stn(info.get("prefix", ""), 155, encoding, errors)
1140 ]
1141
1142 buf = struct.pack("%ds" % BLOCKSIZE, b"".join(parts))
1143 chksum = calc_chksums(buf[-BLOCKSIZE:])[0]
1144 buf = buf[:-364] + bytes("%06o\0" % chksum, "ascii") + buf[-357:]
1145 return buf
1146
1147 @staticmethod
1148 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