Skip to main content

BaseArchive

Base Archive class. Implementations should inherit this class.

Methods


split_leading_dir()

@classmethod
def split_leading_dir(
path: string
) - > tuple

Splits a path into its first directory component and the remaining path, handling both forward and backward slashes.

Parameters

NameTypeDescription
pathstringThe file or directory path to be split

Returns

TypeDescription
tupleA tuple containing the leading directory name and the remaining path string

has_leading_dir()

@classmethod
def has_leading_dir(
paths: list
) - > boolean

Return True if all the paths have the same leading path name (i.e., everything is in one subdirectory in an archive).

Parameters

NameTypeDescription
pathslistA collection of file paths to check for a common leading directory

Returns

TypeDescription
booleanTrue if all paths share a common top-level directory, False otherwise

target_filename()

@classmethod
def target_filename(
to_path: string,
name: string
) - > string

Calculates the absolute target path for an archived file and validates that it resides within the intended destination directory.

Parameters

NameTypeDescription
to_pathstringThe base destination directory where the archive is being extracted
namestringThe relative path of the file as stored within the archive

Returns

TypeDescription
stringThe absolute path where the file should be extracted

extract()

@classmethod
def extract() - > null

Extracts the contents of the archive to the local file system; must be implemented by subclasses.

Returns

TypeDescription
nullNone

list()

@classmethod
def list() - > null

Returns a list of all files and directories contained within the archive; must be implemented by subclasses.

Returns

TypeDescription
nullNone