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
| Name | Type | Description |
|---|---|---|
| path | string | The file or directory path to be split |
Returns
| Type | Description |
|---|---|
tuple | A 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
| Name | Type | Description |
|---|---|---|
| paths | list | A collection of file paths to check for a common leading directory |
Returns
| Type | Description |
|---|---|
boolean | True 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
| Name | Type | Description |
|---|---|---|
| to_path | string | The base destination directory where the archive is being extracted |
| name | string | The relative path of the file as stored within the archive |
Returns
| Type | Description |
|---|---|
string | The 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
| Type | Description |
|---|---|
null | None |
list()
@classmethod
def list() - > null
Returns a list of all files and directories contained within the archive; must be implemented by subclasses.
Returns
| Type | Description |
|---|---|
null | None |