On this page
tarfile.TarInfo
Prev: tarfile.TarFile | Up: tarfile
Rel: tarfile.AbsoluteLinkError, tarfile.AbsolutePathError, tarfile.CompressionError, tarfile.data_filter
Ref: docs.python.org — tarfile.TarInfo
Tags: #public #python3 #stdlib #tarfile
Import
import tarfile
from tarfile import TarInfo
Signature & Overview
tarfile.TarInfo(name='')
Informational class which holds the details about an archive member given by a tar header block.
Methods & Attributes
TarInfo.create_gnu_header(self, info, encoding, errors)— Return the object as a GNU header block sequence.TarInfo.create_pax_global_header(pax_headers)— Return the object as a pax global header block sequence.TarInfo.create_pax_header(self, info, encoding)— Return the object as a ustar header block. If it cannot be represented this way, prepend a pax extended header sequence with supplement information.TarInfo.create_ustar_header(self, info, encoding, errors)— Return the object as a ustar header block.TarInfo.frombuf(buf, encoding, errors)— Construct a TarInfo object from a 512 byte bytes object.TarInfo.fromtarfile(tarfile)— Return the next TarInfo object from TarFile object tarfile.TarInfo.get_info(self)— Return the TarInfo's attributes as a dictionary.TarInfo.isblk(self)— Return True if it is a block device.TarInfo.ischr(self)— Return True if it is a character device.TarInfo.isdev(self)— Return True if it is one of character device, block device or FIFO.TarInfo.isdir(self)— Return True if it is a directory.TarInfo.isfifo(self)— Return True if it is a FIFO.TarInfo.isfile(self)— Return True if the Tarinfo object is a regular file.TarInfo.islnk(self)— Return True if it is a hard link.TarInfo.isreg(self)— Return True if the Tarinfo object is a regular file.TarInfo.issparse(self)—TarInfo.issparsemethod/property.TarInfo.issym(self)— Return True if it is a symbolic link.TarInfo.linkpath(...)— In pax headers, "linkname" is called "linkpath".TarInfo.path(...)— In pax headers, "name" is called "path".TarInfo.replace(self, *, name=<object object at 0x1040b5920>, mtime=<object object at 0x1040b5920>, mode=<object object at 0x1040b5920>, linkname=<object object at 0x1040b5920>, uid=<object object at 0x1040b5920>, gid=<object object at 0x1040b5920>, uname=<object object at 0x1040b5920>, gname=<object object at 0x1040b5920>, deep=True, _KEEP=<object object at 0x1040b5920>)— Return a deep copy of self with the given attributes replaced.TarInfo.tarfile(...)—TarInfo.tarfilemethod/property.TarInfo.tobuf(self, format=2, encoding='utf-8', errors='surrogateescape')— Return a tar header as a string of 512 byte blocks.
Usage
import tarfile
info = tarfile.TarInfo("docs/readme.txt")
info.size = 12
info.mode = 0o644
assert info.isfile() and info.name == "docs/readme.txt"
Gotchas
- Must set
info.sizeaccurately beforetf.addfile(info, fileobj): Leavinginfo.size == 0writes an empty member.
REPL Inspect
from tarfile import TarInfo
help(TarInfo)
Linked from
Related notes
- tuts/python3/stdlib_module/tarfile/TarFile Linked here; links to this page; shared tags: #stdlib, #tarfile
- tuts/python3/stdlib_module/tarfile/AbsoluteLinkError Linked here; shared tags: #stdlib, #tarfile
- tuts/python3/stdlib_module/tarfile/AbsolutePathError Linked here; shared tags: #stdlib, #tarfile
- tuts/python3/stdlib_module/tarfile/CompressionError Linked here; shared tags: #stdlib, #tarfile
- tuts/python3/stdlib_module/tarfile/data_filter Linked here; shared tags: #stdlib, #tarfile
- tuts/python3/stdlib_module/tarfile links to this page; shared tags: #stdlib
- tuts/python3/stdlib_module/tarfile/ExtractError shared tags: #stdlib, #tarfile
- tuts/python3/stdlib_module/tarfile/FilterError shared tags: #stdlib, #tarfile
- tuts/python3/stdlib_module/tarfile/fully_trusted_filter shared tags: #stdlib, #tarfile
- tuts/python3/stdlib_module/tarfile/HeaderError shared tags: #stdlib, #tarfile