No results for

Powered byAlgolia
⚠️ This is archived documentation for v0.31. Go to the latest version

b64encode( input, [encoding] )

suggest edits
ParameterTypeDescription
inputstring / ArrayBuffer (≥ v0.31.0)The input string or ArrayBuffer object to base64 encode.
encoding (optional)stringThe 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.

Returns

TypeDescription
stringThe base64 encoding of the input data.

Example

import { check } from 'k6';
import encoding from 'k6/encoding';
export default function () {
let str = 'hello world';
let enc = 'aGVsbG8gd29ybGQ=';
let buf = new Uint8Array([104, 101, 108, 108, 111, 32, 119, 111, 114, 108, 100]).buffer;
check(null, {
'is encoding correct': () => encoding.b64encode(str) === enc,
'is decoding correct': () => encoding.b64decode(enc) === str,
'is encoding ArrayBuffer correct': () => encoding.b64encode(buf) === enc,
});
}