def _write_file(filename: str, content: str, *, binary: bool = False) -> int:
    """Write a file with the given content."""
    if binary:
        mode = "wb"
        encoding = None
    else:
        mode = "w"
        encoding = "utf-8"

    with open(filename, mode, encoding=encoding) as f:
        return f.write(content)