code wiki / _hdl_build / nx_b64_cli.nx
nx_b64_cli.nx
buildroot/runtime/_hdl_build/nx_b64_cli.nx
about
nx_b64_cli.nx -- base64 a file to stdout (and optionally to a file), and DECODE a base64 file
back to bytes. WHY THIS EXISTS: runtime/nx_base64.nx carries a complete b64_encode/b64_decode
pair and NO main, so the capability could not be INVOKED. The encode half shipped 2026-08-06;
the DECODE half stayed uninvokable -- which made base64 a one-way transport: bytes could leave
the estate as text but text could not become bytes again, so binary INGEST (the rigged-donor
FBX lane, 2026-08-23) had no sovereign door. This adds the missing verb by composing the SAME
lib -- one codec, two verbs.
BUFFER-CAP LAW (operator 2026-08-14: a ceiling that has to be guessed is a defect generator):
the old BC_MAX_IN 8 MiB / BC_MAX_OUT 12 MiB REFUSED any file over 8 MiB -- a 73.6 MB donor FBX
(98 MB as base64) could never pass. For FILE work there is no guess to make: sys_read_file
sizes its buffer from the file, and the OUTPUT bound is ARITHMETIC from the input length
(encode: 4*ceil(n/3) + newline; decode: 3*n/4). Both derived, both announced, no cap remains.
usage: nx_b64_cli <infile> [outfile] encode (unchanged contract)
nx_b64_cli dec <in.b64> <outfile> decode; announces bytes_in/bytes_out
exit 0 ok, 1 usage, 2 unreadable/empty, 3 write-failed
license_tier: ORIGINAL No hw writes (Rule 26). expect_exit: 0
dependencies 2 imports · 0 importers
imports: nx_syscalls.nxnx_base64.nx
imported by: nobody (leaf or entry point)
call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown
structs
| none |
consts
| 21 | const BC_ENC_UNIT_IN: i64 = 3 // encode consumes 3 bytes... |
| 22 | const BC_ENC_UNIT_OUT: i64 = 4 // ...and emits 4 chars; decode is the inverse |
| 23 | const BC_TAIL_SLACK: i64 = 8 // newline + NUL + rounding of the final group |
| 24 | const BC_VERB_DEC: i64 = 100 // 'd' |
| 25 | const BC_EXIT_OK: i64 = 0 |
| 26 | const BC_EXIT_USAGE: i64 = 1 |
| 27 | const BC_EXIT_UNREADABLE: i64 = 2 |
| 28 | const BC_EXIT_WRITEFAIL: i64 = 3 |
functions
| 30 | func bc_puts(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(1, s, n); return 0 } |
| 31 | func bc_putn(v: i64) -> i64 |
| 44 | func bc_eq(a: *u8, b: *u8) -> i64 called by 1: main |
| 51 | func main(argc: i64, argv: *i64) -> i64 |