Skip to content

base64_encode

Class info

Classes

Name Children Inherits
MacOSBase64EncodeCommand
anyenv.os_commands.base64_encode
macOS base64 encode command implementation.
    UnixBase64EncodeCommand
    anyenv.os_commands.base64_encode
    Unix/Linux base64 encode command implementation.
      WindowsBase64EncodeCommand
      anyenv.os_commands.base64_encode
      Windows base64 encode command implementation using PowerShell.

        🛈 DocStrings

        Base64 encode command implementations for different operating systems.

        MacOSBase64EncodeCommand

        Bases: Base64EncodeCommand

        macOS base64 encode command implementation.

        Source code in src/anyenv/os_commands/base64_encode.py
        class MacOSBase64EncodeCommand(Base64EncodeCommand):
            """macOS base64 encode command implementation."""
        
            def create_command(self, path: str) -> str:
                """Generate macOS base64 command.
        
                Args:
                    path: Path to file to encode
        
                Returns:
                    The base64 command string
                """
                # macOS base64 uses -i for input file
                return f"base64 -i {sh_path(path)}"
        
            def parse_command(self, output: str) -> bytes:
                """Parse macOS 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 macOS 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 macOS base64 command.
        
            Args:
                path: Path to file to encode
        
            Returns:
                The base64 command string
            """
            # macOS base64 uses -i for input file
            return f"base64 -i {sh_path(path)}"
        

        parse_command

        parse_command(output: str) -> bytes
        

        Parse macOS 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 macOS base64 output.
        
            Args:
                output: Raw base64 encoded output
        
            Returns:
                Decoded bytes
            """
            cleaned = output.replace("\n", "").replace("\r", "").strip()
            return base64.b64decode(cleaned)
        

        UnixBase64EncodeCommand

        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)
        

        WindowsBase64EncodeCommand

        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)