#!/usr/bin/env python3
"""Convert a file to an ASCII 0/1 binary-text representation."""

from __future__ import annotations

import argparse
from pathlib import Path


def main() -> None:
    parser = argparse.ArgumentParser()
    parser.add_argument("input", type=Path)
    parser.add_argument("output", type=Path)
    parser.add_argument("--line-width", type=int, default=0, help="Insert newlines every N bits; 0 means no wrapping")
    args = parser.parse_args()

    data = args.input.read_bytes()
    bits = "".join(f"{byte:08b}" for byte in data)
    if args.line_width and args.line_width > 0:
        bits = "\n".join(bits[i : i + args.line_width] for i in range(0, len(bits), args.line_width))
        bits += "\n"
    args.output.write_text(bits, encoding="ascii")


if __name__ == "__main__":
    main()
