Skip to content

UnixBase64EncodeCommand

Base classes

Name Children Inherits
Base64EncodeCommand
anyenv.os_commands.base
Base class for base64 encode commands.

⋔ Inheritance diagram

graph TD
  1908942792["base64_encode.UnixBase64EncodeCommand"]
  3600911348["base.Base64EncodeCommand"]
  925645236["abc.ABC"]
  2751680898["builtins.object"]
  3600911348 --> 1908942792
  925645236 --> 3600911348
  2751680898 --> 925645236

🛈 DocStrings

Bases: Base64EncodeCommand

Unix/Linux base64 encode command implementation.

Source code in src/anyenv/os_commands/base64_encode.py
class UnixBase64EncodeCommand(Base64EncodeCommand):
    """Unix/Linux base64 encode command implementation."""

    def create_command(self, path: str) -> str:
        """Generate Unix base64 command.

        Args:
            path: Path to file to encode

        Returns:
            The base64 command string
        """
        return f"base64 {sh_path(path)}"

    def parse_command(self, output: str) -> bytes:
        """Parse Unix base64 output.

        Args:
            output: Raw base64 encoded output

        Returns:
            Decoded bytes
        """
        # Remove any whitespace/newlines that base64 command may add
        cleaned = output.replace("\n", "").replace("\r", "").strip()
        return base64.b64decode(cleaned)

create_command

create_command(path: str) -> str

Generate Unix base64 command.

Parameters:

Name Type Description Default
path str

Path to file to encode

required

Returns:

Type Description
str

The base64 command string

Source code in src/anyenv/os_commands/base64_encode.py
def create_command(self, path: str) -> str:
    """Generate Unix base64 command.

    Args:
        path: Path to file to encode

    Returns:
        The base64 command string
    """
    return f"base64 {sh_path(path)}"

parse_command

parse_command(output: str) -> bytes

Parse Unix base64 output.

Parameters:

Name Type Description Default
output str

Raw base64 encoded output

required

Returns:

Type Description
bytes

Decoded bytes

Source code in src/anyenv/os_commands/base64_encode.py
def parse_command(self, output: str) -> bytes:
    """Parse Unix base64 output.

    Args:
        output: Raw base64 encoded output

    Returns:
        Decoded bytes
    """
    # Remove any whitespace/newlines that base64 command may add
    cleaned = output.replace("\n", "").replace("\r", "").strip()
    return base64.b64decode(cleaned)

:fa-brands-github: Show source on GitHub