MCPcopy Create free account
hub / github.com/microsoft/SandDance / toByteArray

Function toByteArray

docs/app/js/sanddance-app.js:114122–114148  ·  view source on GitHub ↗
(b64)

Source from the content-addressed store, hash-verified

114120 return (validLen + placeHoldersLen) * 3 / 4 - placeHoldersLen;
114121}
114122function toByteArray(b64) {
114123 var tmp;
114124 var lens = getLens(b64);
114125 var validLen = lens[0];
114126 var placeHoldersLen = lens[1];
114127 var arr = new Arr(_byteLength(b64, validLen, placeHoldersLen));
114128 var curByte = 0;
114129 // if there are placeholders, only get up to the last complete 4 chars
114130 var len2 = placeHoldersLen > 0 ? validLen - 4 : validLen;
114131 var i1;
114132 for(i1 = 0; i1 < len2; i1 += 4){
114133 tmp = revLookup[b64.charCodeAt(i1)] << 18 | revLookup[b64.charCodeAt(i1 + 1)] << 12 | revLookup[b64.charCodeAt(i1 + 2)] << 6 | revLookup[b64.charCodeAt(i1 + 3)];
114134 arr[curByte++] = tmp >> 16 & 0xFF;
114135 arr[curByte++] = tmp >> 8 & 0xFF;
114136 arr[curByte++] = tmp & 0xFF;
114137 }
114138 if (placeHoldersLen === 2) {
114139 tmp = revLookup[b64.charCodeAt(i1)] << 2 | revLookup[b64.charCodeAt(i1 + 1)] >> 4;
114140 arr[curByte++] = tmp & 0xFF;
114141 }
114142 if (placeHoldersLen === 1) {
114143 tmp = revLookup[b64.charCodeAt(i1)] << 10 | revLookup[b64.charCodeAt(i1 + 1)] << 4 | revLookup[b64.charCodeAt(i1 + 2)] >> 2;
114144 arr[curByte++] = tmp >> 8 & 0xFF;
114145 arr[curByte++] = tmp & 0xFF;
114146 }
114147 return arr;
114148}
114149function tripletToBase64(num) {
114150 return lookup[num >> 18 & 0x3F] + lookup[num >> 12 & 0x3F] + lookup[num >> 6 & 0x3F] + lookup[num & 0x3F];
114151}

Callers

nothing calls this directly

Calls 2

getLensFunction · 0.70
_byteLengthFunction · 0.70

Tested by

no test coverage detected