Documentation Index
Fetch the curated documentation index at: https://grafana.com/llms.txt
Fetch the complete documentation index at: https://grafana.com/llms-full.txt
Use this file to discover all available pages before exploring further.
STOP! If you are an AI agent or LLM, read this before continuing. This is the HTML version of a Grafana documentation page. Always request the Markdown version instead - HTML wastes context. Get this page as Markdown: https://grafana.com/docs/k6/next/javascript-api/k6-encoding/b64decode.md (append .md) or send Accept: text/markdown to https://grafana.com/docs/k6/next/javascript-api/k6-encoding/b64decode/. For the curated documentation index, use https://grafana.com/llms.txt. For the complete documentation index, use https://grafana.com/llms-full.txt.
This is documentation for the next version of Grafana k6 documentation. For the latest stable release, go to the latest version.
b64decode( input, [encoding], [format] )
Decode the passed base64 encoded input string into the unencoded original input in either binary or string formats.
| Parameter | Type | Description |
|---|---|---|
| input | string | The string to base64 decode. |
| encoding (optional) | string | The base64 encoding to use. Available options are: - “std”: the standard encoding with = padding chars and + and / characters in encoding alphabet. This is the default.- “rawstd”: like std but without = padding characters.- “url”: URL safe version of std, encoding alphabet doesn’t contain + and / characters, but rather - and _ characters.- “rawurl”: like url but without = padding characters. |
| format (optional) | string | If "s" return the data as a string, otherwise if unspecified an ArrayBuffer object is returned. |
Returns
| Type | Description |
|---|---|
| ArrayBuffer / string | The base64 decoded version of the input string in either string or ArrayBuffer format, depending on the format parameter. |
Example
import { check } from 'k6';
import encoding from 'k6/encoding';
export default function () {
const str = 'hello world';
const enc = 'aGVsbG8gd29ybGQ=';
const expBin = new Uint8Array([104, 101, 108, 108, 111, 32, 119, 111, 114, 108, 100]);
check(null, {
'is decoding to string correct': () => encoding.b64decode(enc, 'std', 's') === str,
'is decoding to ArrayBuffer correct': () => {
const decBin = new Uint8Array(encoding.b64decode(enc));
if (decBin.length != expBin.length) return false;
for (let i = 0; i < decBin.length; i++) {
if (decBin[i] !== expBin[i]) return false;
}
return true;
},
});
}Was this page helpful?
Related resources from Grafana Labs

