hfutils.utils.archive

This module provides functionality for identifying archive and compressed files based on their filenames.

It includes a comprehensive list of known archive and compressed file extensions, as well as patterns for identifying split archives and other generic compressed file formats. The main function is_archive_or_compressed() can be used to determine if a given filename represents an archive or compressed file.

The module is useful for file handling operations where it’s necessary to distinguish between regular files and archives or compressed files.

is_archive_or_compressed

hfutils.utils.archive.is_archive_or_compressed(filename: str | PathLike) bool[source]

Determine if the given filename represents an archive or compressed file.

This function checks the filename against a list of known archive and compressed file extensions, as well as patterns for split archives and other generic compressed file formats.

Parameters:

filename (Union[str, os.PathLike]) – The name of the file to check. Can be a string or a path-like object.

Returns:

True if the filename represents an archive or compressed file, False otherwise.

Return type:

bool

Raises:

TypeError – If the filename is not a string or path-like object.

Usage:
>>> is_archive_or_compressed('example.zip')
True
>>> is_archive_or_compressed('document.txt')
False
>>> is_archive_or_compressed('archive.tar.gz')
True
>>> is_archive_or_compressed('split_archive.zip.001')
True