Skip to content

Types

provide.foundation.archive.types

TODO: Add module docstring.

Classes

ArchiveOperation

Bases: IntEnum

Archive operation codes compatible with PSPF/2025 format.

These operation codes match the PSPF/2025 v0 specification to ensure compatibility with flavorpack's package format. The hex values are canonical and must not be changed without updating the PSPF spec.

Values

NONE: No operation (0x00) TAR: POSIX TAR archive bundling (0x01) GZIP: GZIP compression (0x10) BZIP2: BZIP2 compression (0x13) XZ: XZ/LZMA2 compression (0x16) ZSTD: Zstandard compression (0x1B)

Example

from provide.foundation.archive.types import ArchiveOperation op = ArchiveOperation.TAR assert op == 0x01 assert op.name == "TAR"

Functions
from_string classmethod
from_string(name: str) -> ArchiveOperation

Convert string operation name to enum.

Parameters:

Name Type Description Default
name str

Operation name (case-insensitive)

required

Returns:

Type Description
ArchiveOperation

ArchiveOperation enum value

Raises:

Type Description
ValueError

If operation name is invalid

Example

ArchiveOperation.from_string("tar") ArchiveOperation.from_string("GZIP")

Source code in provide/foundation/archive/types.py
@classmethod
def from_string(cls, name: str) -> ArchiveOperation:
    """Convert string operation name to enum.

    Args:
        name: Operation name (case-insensitive)

    Returns:
        ArchiveOperation enum value

    Raises:
        ValueError: If operation name is invalid

    Example:
        >>> ArchiveOperation.from_string("tar")
        <ArchiveOperation.TAR: 1>
        >>> ArchiveOperation.from_string("GZIP")
        <ArchiveOperation.GZIP: 16>

    """
    name_upper = name.upper()
    try:
        return cls[name_upper]
    except KeyError:
        raise ValueError(f"Unknown archive operation: {name}") from None
to_string
to_string() -> str

Convert enum to lowercase string name.

Returns:

Type Description
str

Lowercase operation name

Example

ArchiveOperation.TAR.to_string() 'tar'

Source code in provide/foundation/archive/types.py
def to_string(self) -> str:
    """Convert enum to lowercase string name.

    Returns:
        Lowercase operation name

    Example:
        >>> ArchiveOperation.TAR.to_string()
        'tar'

    """
    return self.name.lower()

Functions

get_operation_from_string

get_operation_from_string(
    op_string: str,
) -> ArchiveOperation

Get operation enum from string (supports extraction aliases).

Parameters:

Name Type Description Default
op_string str

Operation string (e.g., "tar", "untar", "gzip", "gunzip")

required

Returns:

Type Description
ArchiveOperation

ArchiveOperation enum value

Raises:

Type Description
ValueError

If operation string is invalid

Example

get_operation_from_string("tar") get_operation_from_string("untar") # Same as "tar"

Source code in provide/foundation/archive/types.py
def get_operation_from_string(op_string: str) -> ArchiveOperation:
    """Get operation enum from string (supports extraction aliases).

    Args:
        op_string: Operation string (e.g., "tar", "untar", "gzip", "gunzip")

    Returns:
        ArchiveOperation enum value

    Raises:
        ValueError: If operation string is invalid

    Example:
        >>> get_operation_from_string("tar")
        <ArchiveOperation.TAR: 1>
        >>> get_operation_from_string("untar")  # Same as "tar"
        <ArchiveOperation.TAR: 1>

    """
    op_lower = op_string.lower()
    if op_lower not in OPERATION_NAMES:
        raise ValueError(f"Unknown archive operation: {op_string}")
    return OPERATION_NAMES[op_lower]