tencent cloud

文档Performance Testing Service

util.base64Decoding

下载
聚焦模式
字号
最后更新时间: 2025-03-10 17:23:46
During the script execution, util.base64Decoding is used for base64 decoding.
base64Decoding(input: string, encoding?: "std" | "rawstd" | "url" | "rawurl", mode?: "b"): string | ArrayBuffer

Background

The different base64 encoding methods are as follows:
StdEncoding is the standard Base64 encoding as defined in RFC 4648.
RawStdEncoding is the standard raw, unpadded base64 encoding as defined in Section 3.2 of RFC 4648; it is the same as StdEncoding but omits the padding characters.
URLEncoding is the alternate base64 encoding defined in RFC 4648, typically used for URLs and file names.
RawURLEncoding is the unpadded alternate base64 encoding defined in RFC 4648, typically used for URLs and file names; it is the same as URLEncoding but omits the padding characters.

Parameters

Parameter
Type
Description
input
string
The string to be decoded.
encoding (optional)
string
Optional; represents the different encoding methods mentioned above; optional values include "std", "rawstd", "url", and "rawurl". If not set, defaults to "std".
mode (optional)
string
Optional; if not set, the result is of type string. If set to "b", the result is of type ArrayBuffer.

Return

Type
Description
string or ArrayBuffer.
The result obtained through base64 decoding.

Usage Examples

Use the base64Decoding method without specifying encoding:
import util from 'pts/util';

export default function () {
// Hello, world
console.log(util.base64Decoding('SGVsbG8sIHdvcmxk'));
}
Use the base64Decoding method with a specified encoding:
import util from 'pts/util';

export default function () {
// http://www.example.com
console.log(util.base64Decoding('aHR0cDovL3d3dy5leGFtcGxlLmNvbQ==', 'url'));
}
Use the base64Decoding method with a specified mode:
import util from 'pts/util';

export default function () {
// [object ArrayBuffer]
console.log(util.base64Decoding('SGVsbG8sIHdvcmxk', 'std', 'b'));
}


帮助和支持

本页内容是否解决了您的问题?

填写满意度调查问卷,共创更好文档体验。

文档反馈