Liking cljdoc? Tell your friends :D

koine.codec

Base64, portable.

Standard base64 with padding (RFC 4648 §4) — NOT the URL-safe alphabet. That is what MCP image / blob content blocks use, which is what this exists for.

Strings are treated as UTF-8 both ways. encode also accepts a byte array (from koine.fs/read-bytes), which is the case that matters for binary content; decode returns a string and decode-bytes the raw bytes.

The TRANSFORM is pure clojure.core (see b64-encode-vals below) — an alphabet substitution is arithmetic, not a host capability. Only two things are host-shaped and they are small: turning a string into UTF-8 byte values and back. Where a host already ships base64 over exactly the types we have (the JVM, cljgo, let-go for strings), that route is used instead: it is faster, and it is one less thing to be subtly wrong about.

Base64, portable.

Standard base64 with padding (RFC 4648 §4) — NOT the URL-safe alphabet. That
is what MCP `image` / `blob` content blocks use, which is what this exists for.

Strings are treated as UTF-8 both ways. `encode` also accepts a byte array
(from `koine.fs/read-bytes`), which is the case that matters for binary
content; `decode` returns a string and `decode-bytes` the raw bytes.

The TRANSFORM is pure `clojure.core` (see `b64-encode-vals` below) — an
alphabet substitution is arithmetic, not a host capability. Only two things
are host-shaped and they are small: turning a string into UTF-8 byte values
and back. Where a host already ships base64 over exactly the types we have
(the JVM, cljgo, let-go for strings), that route is used instead: it is
faster, and it is one less thing to be subtly wrong about.
raw docstring

b64-decode-valsclj/s

(b64-decode-vals s)

Base64 string -> a vector of UNSIGNED byte values. Pure.

Base64 string -> a vector of UNSIGNED byte values. Pure.
sourceraw docstring

b64-encode-valsclj/s

(b64-encode-vals vals)

Base64 of a seq of UNSIGNED byte values (0-255). Pure; identical everywhere.

Base64 of a seq of UNSIGNED byte values (0-255). Pure; identical everywhere.
sourceraw docstring

decodeclj/s

(decode s)

Decode base64 string s to a UTF-8 string. For binary payloads use decode-bytes — a byte that is not valid UTF-8 does not survive this.

Decode base64 string `s` to a UTF-8 string. For binary payloads use
`decode-bytes` — a byte that is not valid UTF-8 does not survive this.
sourceraw docstring

decode-bytesclj/s

(decode-bytes s)

Decode base64 string s to a byte array.

Decode base64 string `s` to a byte array.
sourceraw docstring

encodeclj/s

(encode x)

Base64-encode x — a string (UTF-8) or a byte array. Returns a string.

Base64-encode `x` — a string (UTF-8) or a byte array. Returns a string.
sourceraw docstring

cljdoc builds & hosts documentation for Clojure/Script libraries

Keyboard shortcuts
Ctrl+kJump to recent docs
Move to previous article
Move to next article
Ctrl+/Jump to the search field
× close