Skip to main content

TarArchive

This class provides functionality for managing and extracting TAR archive files by wrapping the standard tarfile library. It supports listing archive contents and extracting members to a specified path while automatically handling directory creation and permission preservation. The class also includes logic to detect and strip leading directories during the extraction process.

Attributes

AttributeTypeDescription
_archivetarfile.TarFileThe underlying tarfile object used to manage the archive's contents and file operations.

Constructor

Signature

def TarArchive(
file: str or file-like object
) - > null

Parameters

NameTypeDescription
filestr or file-like objectThe path to the tar archive or a file-like object containing the archive.

Signature

def TarArchive(
file: string
) - > null

Parameters

NameTypeDescription
filestringThe file path or file-like object representing the tar archive to be managed.

Methods


list()

@classmethod
def list(
*args: any,
**kwargs: any
) - > null

Prints a verbose listing of the archive contents to standard output.

Parameters

NameTypeDescription
*argsanyPositional arguments passed directly to the underlying tarfile.list method.
**kwargsanyKeyword arguments passed directly to the underlying tarfile.list method.

Returns

TypeDescription
nullNone

extract()

@classmethod
def extract(
to_path: string
) - > null

Extracts the contents of the tar archive to a specified directory while normalizing leading directory structures and preserving file permissions.

Parameters

NameTypeDescription
to_pathstringThe destination directory path where the archive contents will be extracted.

Returns

TypeDescription
nullNone

close()

@classmethod
def close() - > null

Closes the underlying tar file handle to release system resources.

Returns

TypeDescription
nullNone