"""Utility functions for ZeptoMail."""

from __future__ import annotations

import base64
import os


def bytes_to_base64(data: bytes) -> str:
    """Encode *data* to a base64 string.

    Args:
        data: Raw bytes to encode.

    Returns:
        Base64-encoded string.
    """
    return base64.b64encode(data).decode("utf-8")


def file_to_base64(path: str | os.PathLike) -> str:
    """Read a file and return its base64-encoded contents.

    Args:
        path: Path to the file.

    Returns:
        Base64-encoded string of the file contents.

    Raises:
        FileNotFoundError: If the file does not exist.
    """
    with open(path, "rb") as fh:
        return bytes_to_base64(fh.read())
