Skip to content

Commit a30aafb

Browse files
author
Ivan Mirić
committed
Document ArrayBuffer support in k6/encoding module
Part of #233
1 parent 99a8fe7 commit a30aafb

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

src/data/markdown/docs/02 javascript api/05 k6-encoding/b64encode- input- -encoding- -.md

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
---
22
title: 'b64encode( input, [encoding] )'
3-
description: 'Base64 encode a string.'
3+
description: 'Encode data in base64.'
44
---
55

6-
| Parameter | Type | Description |
7-
| ------------------- | ------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
8-
| input | string | The string to base64 encode. |
6+
| Parameter | Type | Description |
7+
| ------------------- | ------ | ------------------------------------------------------------------------ |
8+
| input | string / ArrayBuffer | The input string or `ArrayBuffer` object to base64 encode. |
99
| encoding (optional) | string | The base64 encoding to use.<br/>Available options are:<br/>- **"std"**: the standard encoding with `=` padding chars and `+` and `/` characters in encoding alphabet. This is the default.<br/>- **"rawstd"**: like `std` but without `=` padding characters.<br/>- **"url"**: URL safe version of `std`, encoding alphabet doesn't contain `+` and `/` characters, but rather `-` and `_` characters.<br/>- **"rawurl"**: like `url` but without `=` padding characters. |
1010

1111
### Returns
1212

13-
| Type | Description |
14-
| ------ | ------------------------------------------------- |
15-
| string | The base64 encoded version of the `input` string. |
13+
| Type | Description |
14+
| ------ | ---------------------------------------- |
15+
| string | The base64 encoding of the `input` data. |
1616

1717
### Example
1818

@@ -25,9 +25,11 @@ import encoding from 'k6/encoding';
2525
export default function () {
2626
let str = 'hello world';
2727
let enc = 'aGVsbG8gd29ybGQ=';
28+
let buf = new Uint8Array([104, 101, 108, 108, 111, 32, 119, 111, 114, 108, 100]).buffer;
2829
check(null, {
2930
'is encoding correct': () => encoding.b64encode(str) === enc,
3031
'is decoding correct': () => encoding.b64decode(enc) === str,
32+
'is encoding ArrayBuffer correct': () => encoding.b64encode(buf) === enc,
3133
});
3234
}
3335
```

0 commit comments

Comments
 (0)