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

Function calc_chksums

tools/python-3.11.9-amd64/Lib/tarfile.py:226–237  ·  view source on GitHub ↗

Calculate the checksum for a member's header by summing up all characters except for the chksum field which is treated as if it was filled with spaces. According to the GNU tar sources, some tars (Sun and NeXT) calculate chksum with signed char, which will be differen

(buf)

Source from the content-addressed store, hash-verified

224 return s
225
226def calc_chksums(buf):
227 """Calculate the checksum for a member's header by summing up all
228 characters except for the chksum field which is treated as if
229 it was filled with spaces. According to the GNU tar sources,
230 some tars (Sun and NeXT) calculate chksum with signed char,
231 which will be different if there are chars in the buffer with
232 the high bit set. So we calculate two checksums, unsigned and
233 signed.
234 """
235 unsigned_chksum = 256 + sum(struct.unpack_from("148B8x356B", buf))
236 signed_chksum = 256 + sum(struct.unpack_from("148b8x356b", buf))
237 return unsigned_chksum, signed_chksum
238
239def copyfileobj(src, dst, length=None, exception=OSError, bufsize=None):
240 """Copy length bytes from fileobj src to fileobj dst.

Callers 2

_create_headerMethod · 0.85
frombufMethod · 0.85

Calls 1

sumFunction · 0.50

Tested by

no test coverage detected