Base64

lib/Base64.gob

Base64 as RFC 4648 §4 defines it: the standard alphabet, A-Z a-z 0-9 + /, with = padding.

Base64.encode(String.toBytes("Man"))      -- "TWFu"
Base64.decode("TWE=")                      -- Some([77, 97])

Bytes go in and come out, since base64 exists to carry bytes that are not text; a caller that has text converts it with String.toBytes and String.fromBytes.

Decoding is strict. It takes exactly what encode writes and refuses everything else: no line breaks or spaces, no missing padding, no = except at the end, and no bits set after the last byte (RFC 4648 §3.5). So each byte string has one encoding, and two decoders that compare encoded text cannot disagree about what it holds.

fun encode : [Index c, Length c, Key c ~ Int, Value c ~ Byte] fun(c) -> String

Returns bytes encoded, padded to a multiple of four characters.

fun decode : fun(String) -> Option (Array Byte)

Returns the bytes text encodes, or None if it is not exactly what encode would write for them.