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
| Attribute | Type | Description |
|---|---|---|
| _archive | tarfile.TarFile | The 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
| Name | Type | Description |
|---|---|---|
| file | str or file-like object | The path to the tar archive or a file-like object containing the archive. |
Signature
def TarArchive(
file: string
) - > null
Parameters
| Name | Type | Description |
|---|---|---|
| file | string | The 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
| Name | Type | Description |
|---|---|---|
| *args | any | Positional arguments passed directly to the underlying tarfile.list method. |
| **kwargs | any | Keyword arguments passed directly to the underlying tarfile.list method. |
Returns
| Type | Description |
|---|---|
null | None |
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
| Name | Type | Description |
|---|---|---|
| to_path | string | The destination directory path where the archive contents will be extracted. |
Returns
| Type | Description |
|---|---|
null | None |
close()
@classmethod
def close() - > null
Closes the underlying tar file handle to release system resources.
Returns
| Type | Description |
|---|---|
null | None |