Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Function

base64 — encode/decode Base64 strings

Synopsis

base64(b: bytes) -> string
base64(s: string) -> bytes

Description

The base64 function encodes a bytes value b as a Base64 string, or decodes a Base64 string s into a bytes value.

Examples


Encode byte sequence 0x010203 into its Base64 string

# spq
values base64(this)
# input
0x010203
# expected output
"AQID"

Decode “AQID” into byte sequence 0x010203

# spq
values base64(this)
# input
"AQID"
# expected output
0x010203

Encode ASCII string into Base64-encoded string

# spq
values base64(this::bytes)
# input
"hello, world"
# expected output
"aGVsbG8sIHdvcmxk"

Decode a Base64 string and cast the decoded bytes to a string

# spq
values base64(this)::string
# input
"aGVsbG8gd29ybGQ="
# expected output
"hello world"