MCPcopy Index your code
hub / github.com/python/cpython / addfile

Method addfile

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

2359 self.addfile(tarinfo)
2360
2361 def addfile(self, tarinfo, fileobj=None):
2362 """Add the TarInfo object 'tarinfo' to the archive. If 'tarinfo' represents
2363 a non zero-size regular file, the 'fileobj' argument should be a binary file,
2364 and tarinfo.size bytes are read from it and added to the archive.
2365 You can create TarInfo objects directly, or by using gettarinfo().
2366 """
2367 self._check("awx")
2368
2369 if fileobj is None and tarinfo.isreg() and tarinfo.size != 0:
2370 raise ValueError("fileobj not provided for non zero-size regular file")
2371
2372 tarinfo = copy.copy(tarinfo)
2373
2374 buf = tarinfo.tobuf(self.format, self.encoding, self.errors)
2375 self.fileobj.write(buf)
2376 self.offset += len(buf)
2377 bufsize=self.copybufsize
2378 # If there's data to follow, append it.
2379 if fileobj is not None:
2380 copyfileobj(fileobj, self.fileobj, tarinfo.size, bufsize=bufsize)
2381 blocks, remainder = divmod(tarinfo.size, BLOCKSIZE)
2382 if remainder > 0:
2383 self.fileobj.write(NUL * (BLOCKSIZE - remainder))
2384 blocks += 1
2385 self.offset += blocks * BLOCKSIZE
2386
2387 self.members.append(tarinfo)
2388
2389 def _get_filter_function(self, filter):
2390 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 7

_checkMethod · 0.95
isregMethod · 0.80
tobufMethod · 0.80
copyfileobjFunction · 0.70
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