Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
export function stringToUtf8ByteArray(str) {
if (typeof str !== 'string') {
str = str.toString();
}
const res = Buffer.from(str, 'utf-8');
return res;
}
export function utf8ByteArrayToString(ba) {
if (!Buffer.isBuffer(ba)) {
ba = Buffer.from(ba);
}
const res = ba.toString('utf-8');
return res;
}
export function stringToUtf8Base64(str) {
if (!Buffer.isBuffer(str)) {
if (typeof str !== 'string') {
str = str.toString();
}
str = Buffer.from(str, 'utf-8');
}
const res = str.toString('base64');
return res;
}
export function utf8Base64ToString(strBase64) {
if (!Buffer.isBuffer(strBase64)) {
if (typeof strBase64 !== 'string') {
strBase64 = strBase64.toString();
}
strBase64 = Buffer.from(strBase64, 'base64');
}
const res = strBase64.toString('utf-8');
return res;
}
export function base64ToByteArray(strBase64) {
if (typeof strBase64 !== 'string') {
strBase64 = strBase64.toString();
}
const res = Buffer.from(strBase64, 'base64');
return res;
}
export function byteArrayToBase64(ba) {
if (!Buffer.isBuffer(ba)) {
ba = Buffer.from(ba);
}
const res = ba.toString('base64');
return res;
}