2022-02-08 12:16:20 +00:00
|
|
|
function base64DecToArr (sBase64) {
|
2022-02-08 12:17:21 +00:00
|
|
|
/*\
|
|
|
|
|*|
|
|
|
|
|*| Base64 / binary data / UTF-8 strings utilities
|
|
|
|
|*|
|
|
|
|
|*| https://developer.mozilla.org/en-US/docs/Web/JavaScript/Base64_encoding_and_decoding
|
|
|
|
|*|
|
|
|
|
\*/
|
|
|
|
|
|
|
|
/* Array of bytes to Base64 string decoding */
|
|
|
|
|
|
|
|
function b64ToUint6 (nChr) {
|
|
|
|
|
|
|
|
return nChr > 64 && nChr < 91 ?
|
|
|
|
nChr - 65
|
|
|
|
: nChr > 96 && nChr < 123 ?
|
|
|
|
nChr - 71
|
|
|
|
: nChr > 47 && nChr < 58 ?
|
|
|
|
nChr + 4
|
|
|
|
: nChr === 43 ?
|
|
|
|
62
|
|
|
|
: nChr === 47 ?
|
|
|
|
63
|
|
|
|
:
|
|
|
|
0;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
var
|
2022-02-08 12:16:20 +00:00
|
|
|
nInLen = sBase64.length,
|
|
|
|
nOutLen = nInLen * 3 + 1 >> 2, taBytes = new Uint8Array(nOutLen);
|
2022-02-08 12:17:21 +00:00
|
|
|
|
|
|
|
for (var nMod3, nMod4, nUint24 = 0, nOutIdx = 0, nInIdx = 0; nInIdx < nInLen; nInIdx++) {
|
|
|
|
nMod4 = nInIdx & 3;
|
2022-02-08 12:16:20 +00:00
|
|
|
nUint24 |= b64ToUint6(sBase64.charCodeAt(nInIdx)) << 6 * (3 - nMod4);
|
2022-02-08 12:17:21 +00:00
|
|
|
if (nMod4 === 3 || nInLen - nInIdx === 1) {
|
|
|
|
for (nMod3 = 0; nMod3 < 3 && nOutIdx < nOutLen; nMod3++, nOutIdx++) {
|
|
|
|
taBytes[nOutIdx] = nUint24 >>> (16 >>> nMod3 & 24) & 255;
|
|
|
|
}
|
|
|
|
nUint24 = 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return taBytes;
|
|
|
|
}
|