Skip to content

WindowsBase64EncodeCommand

Base classes

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

⋔ Inheritance diagram

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

🛈 DocStrings

Bases: Base64EncodeCommand

Windows base64 encode command implementation using PowerShell.

Source code in src/anyenv/os_commands/base64_encode.py
class WindowsBase64EncodeCommand(Base64EncodeCommand):
    """Windows base64 encode command implementation using PowerShell."""

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

        Args:
            path: Path to file to encode

        Returns:
            The PowerShell command string
        """
        # Use PowerShell to read file and convert to base64
        path_expr = f"(Resolve-Path -LiteralPath {ps_literal(path)}).ProviderPath"
        return powershell(f"[Convert]::ToBase64String([IO.File]::ReadAllBytes({path_expr}))")

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

        Args:
            output: Raw base64 encoded output

        Returns:
            Decoded bytes
        """
        cleaned = output.replace("\n", "").replace("\r", "").strip()
        return base64.b64decode(cleaned)

create_command

create_command(path: str) -> str

Generate PowerShell base64 encode command.

Parameters:

Name Type Description Default
path str

Path to file to encode

required

Returns:

Type Description
str

The PowerShell command string

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

    Args:
        path: Path to file to encode

    Returns:
        The PowerShell command string
    """
    # Use PowerShell to read file and convert to base64
    path_expr = f"(Resolve-Path -LiteralPath {ps_literal(path)}).ProviderPath"
    return powershell(f"[Convert]::ToBase64String([IO.File]::ReadAllBytes({path_expr}))")

parse_command

parse_command(output: str) -> bytes

Parse PowerShell 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 PowerShell base64 output.

    Args:
        output: Raw base64 encoded output

    Returns:
        Decoded bytes
    """
    cleaned = output.replace("\n", "").replace("\r", "").strip()
    return base64.b64decode(cleaned)

:fa-brands-github: Show source on GitHub