Skip to content

archive

Class info

🛈 DocStrings

Binary archive extraction utilities.

extract_binary

extract_binary(archive_path: Path, binary_name: str, dest_dir: Path) -> Path

Extract a named binary from an archive, or copy it if not an archive.

Supports ZIP and TAR (gz/bz2/xz) archives. If archive_path is not a recognised archive format the file is copied directly to dest_dir.

Returns the path to the extracted/copied binary.

Source code in src/aclientp/registry/archive.py
def extract_binary(archive_path: Path, binary_name: str, dest_dir: Path) -> Path:
    """Extract a named binary from an archive, or copy it if not an archive.

    Supports ZIP and TAR (gz/bz2/xz) archives. If *archive_path* is not a
    recognised archive format the file is copied directly to *dest_dir*.

    Returns the path to the extracted/copied binary.
    """
    dest_path = dest_dir / binary_name
    dest_dir.mkdir(parents=True, exist_ok=True)

    if zipfile.is_zipfile(archive_path):
        return _extract_from_zip(archive_path, binary_name, dest_path)

    if tarfile.is_tarfile(archive_path):
        return _extract_from_tar(archive_path, binary_name, dest_path)

    # Not an archive — copy directly
    shutil.copy(archive_path, dest_path)
    return dest_path