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

Function itn

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

Convert a python number to a number field.

(n, digits=8, format=DEFAULT_FORMAT)

Source from the content-addressed store, hash-verified

194 return n
195
196def itn(n, digits=8, format=DEFAULT_FORMAT):
197 """Convert a python number to a number field.
198 """
199 # POSIX 1003.1-1988 requires numbers to be encoded as a string of
200 # octal digits followed by a null-byte, this allows values up to
201 # (8**(digits-1))-1. GNU tar allows storing numbers greater than
202 # that if necessary. A leading 0o200 or 0o377 byte indicate this
203 # particular encoding, the following digits-1 bytes are a big-endian
204 # base-256 representation. This allows values up to (256**(digits-1))-1.
205 # A 0o200 byte indicates a positive number, a 0o377 byte a negative
206 # number.
207 original_n = n
208 n = int(n)
209 if 0 <= n < 8 ** (digits - 1):
210 s = bytes("%0*o" % (digits - 1, n), "ascii") + NUL
211 elif format == GNU_FORMAT and -256 ** (digits - 1) <= n < 256 ** (digits - 1):
212 if n >= 0:
213 s = bytearray([0o200])
214 else:
215 s = bytearray([0o377])
216 n = 256 ** digits + n
217
218 for i in range(digits - 1):
219 s.insert(1, n & 0o377)
220 n >>= 8
221 else:
222 raise ValueError("overflow in number field")
223
224 return s
225
226def calc_chksums(buf):
227 """Calculate the checksum for a member&#x27;s header by summing up all

Callers 1

_create_headerMethod · 0.85

Calls 1

insertMethod · 0.45

Tested by

no test coverage detected