Skip to content

Commit e4b7275

Browse files
committed
docs(readme): document the Elixir ~PB compile-time sigil
Verified examples (glyphs captured from the reference encoder, round-trip checked through Elixir decode/1): Hello, World! <-> Hello٫␣Worldǃ and a heredoc "·OK" -> <<0, "OK">>.
1 parent d147967 commit e4b7275

1 file changed

Lines changed: 29 additions & 0 deletions

File tree

README.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,35 @@ cat input.bin | ./bin/printable-binary-node.js -f=8x10 > encoded.txt
261261

262262
Supported flags: `-d/--decode`, `-f/--format NxM`, `-s/--spaces`, `--mappings*`, `-h/--help`. The CLI shares the exact encode/decode implementation with the browser UI.
263263

264+
### As an Elixir `~PB` Sigil (compile-time)
265+
266+
The `~PB` sigil decodes printable-binary glyphs to a **raw binary at compile
267+
time**, so you can embed binary data legibly inline in Elixir source (no
268+
separate fixture files) with zero runtime cost — the decoded bytes are baked
269+
straight into the compiled BEAM module. A literal `"` never appears in the
270+
encoding, so a `"""` heredoc can safely hold multi-line payloads.
271+
272+
```elixir
273+
import PrintableBinary
274+
275+
# Decoded to raw bytes at COMPILE time, then trivially assigned to a variable.
276+
# (Letters/digits pass through; comma -> ٫, space -> ␣, ! -> ǃ, etc.)
277+
greeting = ~PB"Hello٫␣Worldǃ" # => "Hello, World!"
278+
279+
# Heredoc form — whitespace is ignored, so wrapped/pasted glyphs are safe:
280+
blob = ~PB"""
281+
·OK
282+
""" # => <<0, "OK">> (byte 0 -> ·)
283+
284+
# Runtime helper for dynamic (non-literal) input:
285+
PrintableBinary.decode(encoded) # => raw binary
286+
```
287+
288+
Generate the glyphs for any file with the CLI (`printable-binary secret.bin`)
289+
and paste them between the sigil delimiters. See `elixir/` for the module and
290+
tests; the `test-elixir` CI check verifies the decoder against the Zig encoder
291+
(an independent oracle) across all 256 byte values plus random multi-byte input.
292+
264293
### Character Map
265294

266295
Every CLI (and the WASM build, when built) ships with the canonical 256-entry table embedded, so you can always inspect it:

0 commit comments

Comments
 (0)