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

Method addfile

Lib/tarfile.py:2342–2368  ·  view source on GitHub ↗

Add the TarInfo object 'tarinfo' to the archive. If 'tarinfo' represents a non zero-size regular file, the 'fileobj' argument should be a binary file, and tarinfo.size bytes are read from it and added to the archive. You can create TarInfo objects directly, or by usi

(self, tarinfo, fileobj=None)

Source from the content-addressed store, hash-verified

2340 self.addfile(tarinfo)
2341
2342 def addfile(self, tarinfo, fileobj=None):
2343 """Add the TarInfo object 'tarinfo' to the archive. If 'tarinfo' represents
2344 a non zero-size regular file, the 'fileobj' argument should be a binary file,
2345 and tarinfo.size bytes are read from it and added to the archive.
2346 You can create TarInfo objects directly, or by using gettarinfo().
2347 """
2348 self._check("awx")
2349
2350 if fileobj is None and tarinfo.isreg() and tarinfo.size != 0:
2351 raise ValueError("fileobj not provided for non zero-size regular file")
2352
2353 tarinfo = copy.copy(tarinfo)
2354
2355 buf = tarinfo.tobuf(self.format, self.encoding, self.errors)
2356 self.fileobj.write(buf)
2357 self.offset += len(buf)
2358 bufsize=self.copybufsize
2359 # If there's data to follow, append it.
2360 if fileobj is not None:
2361 copyfileobj(fileobj, self.fileobj, tarinfo.size, bufsize=bufsize)
2362 blocks, remainder = divmod(tarinfo.size, BLOCKSIZE)
2363 if remainder > 0:
2364 self.fileobj.write(NUL * (BLOCKSIZE - remainder))
2365 blocks += 1
2366 self.offset += blocks * BLOCKSIZE
2367
2368 self.members.append(tarinfo)
2369
2370 def _get_filter_function(self, filter):
2371 if filter is None:

Callers 15

addMethod · 0.95
test_fileobj_no_closeMethod · 0.80
test_eof_markerMethod · 0.80
test_100_char_nameMethod · 0.80
test_missing_fileobjMethod · 0.80
_compressed_tarMethod · 0.80
_testMethod · 0.80
_testMethod · 0.80

Calls 9

_checkMethod · 0.95
lenFunction · 0.85
isregMethod · 0.80
tobufMethod · 0.80
copyfileobjFunction · 0.70
divmodFunction · 0.50
copyMethod · 0.45
writeMethod · 0.45
appendMethod · 0.45

Tested by 15

test_fileobj_no_closeMethod · 0.64
test_eof_markerMethod · 0.64
test_100_char_nameMethod · 0.64
test_missing_fileobjMethod · 0.64
_compressed_tarMethod · 0.64
_testMethod · 0.64
_testMethod · 0.64