Skip to main content
Version: v1.15.0

base64

Function

base64 encode/decode Base64 strings

Synopsis

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

Description

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

Examples

Encode byte sequence 0x010203 into its Base64 string:

echo '0x010203' | zq -z 'yield base64(this)' -

=>

"AQID"

Decode "AQID" into byte sequence 0x010203:

echo '"AQID"' | zq -z 'yield base64(this)' -

=>

0x010203

Encode ASCII string into Base64-encoded string:

echo '"hello, world"' | zq -z 'yield base64(bytes(this))' -

=>

"aGVsbG8sIHdvcmxk"

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

echo '"aGVsbG8gd29ybGQ="' | zq -z 'yield string(base64(this))' -

=>

"hello world"