Skip to main content

ZipArchive

This class provides functionality for managing and extracting ZIP archive files by extending the BaseArchive interface. It supports listing archive contents, extracting files to a specified path while preserving directory structures, and maintaining file permissions. The class handles leading directory normalization and ensures all necessary parent directories are created during the extraction process.

Attributes

AttributeTypeDescription
_archivezipfile.ZipFileThe underlying zipfile.ZipFile instance used to manage the archive's contents and metadata.

Constructor

Signature

def ZipArchive(
file: Any
)

Parameters

NameTypeDescription
fileAnyThe file-like object or path to the zip archive to be opened.

Signature

def ZipArchive(
file: str | file-like object
) - > null

Parameters

NameTypeDescription
file`strfile-like object`

Methods


list()

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

Prints a table of contents for the zip archive to sys.stdout.

Parameters

NameTypeDescription
*argsanyPositional arguments passed directly to the underlying zipfile.printdir method
**kwargsanyKeyword arguments passed directly to the underlying zipfile.printdir method

Returns

TypeDescription
nullNone

extract()

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

Extracts all members of the archive to the specified destination path while preserving file permissions and handling leading directories.

Parameters

NameTypeDescription
to_pathstrThe local filesystem directory where the archive contents should be extracted

Returns

TypeDescription
nullNone

close()

@classmethod
def close() - > null

Closes the underlying zip archive file handle to release system resources.

Returns

TypeDescription
nullNone