Skip to main content
The k6/encoding module provides base64 encoding and decoding functionality as defined by RFC4648.

Import

Functions

b64encode()

Encodes data in base64 format.
string | ArrayBuffer
required
The input string or ArrayBuffer object to base64 encode.
string
default:"std"
The base64 encoding to use:
  • "std" - Standard encoding with = padding and +// characters (default)
  • "rawstd" - Standard encoding without = padding
  • "url" - URL-safe encoding with -/_ instead of +//
  • "rawurl" - URL-safe encoding without = padding
string
The base64 encoding of the input data.

b64decode()

Decodes a base64 encoded string into the original unencoded input.
string
required
The string to base64 decode.
string
default:"std"
The base64 encoding to use:
  • "std" - Standard encoding with = padding and +// characters (default)
  • "rawstd" - Standard encoding without = padding
  • "url" - URL-safe encoding with -/_ instead of +//
  • "rawurl" - URL-safe encoding without = padding
string
Output format:
  • "s" - Return as string
  • Unspecified - Return as ArrayBuffer (default)
ArrayBuffer | string
The base64 decoded version of the input in either string or ArrayBuffer format.

Encoding Types

Standard (std)

Default base64 encoding with = padding characters and +// in the alphabet.

Raw Standard (rawstd)

Standard encoding without = padding characters.

URL-safe (url)

URL-safe encoding using - and _ instead of + and /, with padding.

Raw URL-safe (rawurl)

URL-safe encoding without = padding characters.

Use Cases

  • Encoding binary data for HTTP headers or URLs
  • Encoding authentication credentials (Basic Auth)
  • Working with Base64-encoded API payloads
  • Converting between binary and text representations
  • Handling file uploads as base64 strings
Use URL-safe encoding (url or rawurl) when the encoded data will be used in URLs or filenames to avoid special characters.