Skip to main content

Binaries

The Binaries category holds functions for encoding, decoding, and assembling binary data. In TransformScript there is no separate binary value type: binary data is just a String of bytes, so these functions take and return ordinary strings. Alongside the base64/hex codecs, the category includes line helpers (readLinesWith / writeLinesWith) for turning byte data into an array of text lines and back, with an explicit charset.

Each function is callable in prefix form fn(s, …) or postfix/UFCS form s fn(…).

FunctionSignatureDescriptionExample
toBase64(:string)Encodes the bytes as a strict (RFC 4648, no line breaks) Base64 string.toBase64("abc")"YWJj"
fromBase64(:string)Decodes strict Base64 back to bytes; raises on invalid input.fromBase64("YWJj")"abc"
toHex(:any?)Hex-encodes a String (byte-by-byte) or a Number (as base-16 digits). Returns null for null.toHex("abc")"616263"; toHex(255)"ff"
fromHex(:string?, :string?)Decodes a hex string (optional 0x prefix). With mode "binary" returns bytes, "number" returns the integer value; with no mode it auto-detects, returning a String when the bytes are all printable, otherwise the Number.fromHex("616263")"abc"; fromHex("ff")255; fromHex("ff", "binary")"\xFF"
concatWith(:string, :string)Concatenates two byte strings (left + right).concatWith("foo", "bar")"foobar"
readLinesWith(:string, :string)Re-interprets the bytes in the given charset and converts to UTF-8, then splits on \r\n, \r, or \n into an array of lines.readLinesWith("a\nb\nc", "UTF-8")["a", "b", "c"]
writeLinesWith(:array, :string?)Joins the array into a single byte string with \n between entries (null entries become empty), encoding the result with the given charset (defaults to UTF-8).writeLinesWith(["a", "b", "c"], "UTF-8")"a\nb\nc"