b64decode( input, [encoding], [format] )
Decode the passed base64 encoded input
string into the unencoded original input in either binary or string formats.
Returns
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;
},
});
}