Skip to content

Commit

Permalink
Document ArrayBuffer support in k6/encoding module
Browse files Browse the repository at this point in the history
Part of #233
  • Loading branch information
Ivan Mirić committed Mar 15, 2021
1 parent 4258120 commit 7970823
Showing 1 changed file with 9 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
---
title: 'b64encode( input, [encoding] )'
description: 'Base64 encode a string.'
description: 'Encode data in base64.'
---

| Parameter | Type | Description |
| ------------------- | ------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| input | string | The string to base64 encode. |
| Parameter | Type | Description |
| ------------------- | ------ | ------------------------------------------------------------------------ |
| input | string / ArrayBuffer | The input string or `ArrayBuffer` object to base64 encode. |
| 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. |

### Returns

| Type | Description |
| ------ | ------------------------------------------------- |
| string | The base64 encoded version of the `input` string. |
| Type | Description |
| ------ | ---------------------------------------- |
| string | The base64 encoding of the `input` data. |

### Example

Expand All @@ -25,9 +25,11 @@ 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,
});
}
```
Expand Down

0 comments on commit 7970823

Please sign in to comment.