MCPcopy Create free account
hub / github.com/TruthHun/BookStack / toByteArray

Function toByteArray

static/word2md/mammoth.browser.js:3950–3979  ·  view source on GitHub ↗
(b64)

Source from the content-addressed store, hash-verified

3948}
3949
3950function toByteArray (b64) {
3951 var i, j, l, tmp, placeHolders, arr
3952 var len = b64.length
3953 placeHolders = placeHoldersCount(b64)
3954
3955 arr = new Arr(len * 3 / 4 - placeHolders)
3956
3957 // if there are placeholders, only get up to the last complete 4 chars
3958 l = placeHolders > 0 ? len - 4 : len
3959
3960 var L = 0
3961
3962 for (i = 0, j = 0; i < l; i += 4, j += 3) {
3963 tmp = (revLookup[b64.charCodeAt(i)] << 18) | (revLookup[b64.charCodeAt(i + 1)] << 12) | (revLookup[b64.charCodeAt(i + 2)] << 6) | revLookup[b64.charCodeAt(i + 3)]
3964 arr[L++] = (tmp >> 16) & 0xFF
3965 arr[L++] = (tmp >> 8) & 0xFF
3966 arr[L++] = tmp & 0xFF
3967 }
3968
3969 if (placeHolders === 2) {
3970 tmp = (revLookup[b64.charCodeAt(i)] << 2) | (revLookup[b64.charCodeAt(i + 1)] >> 4)
3971 arr[L++] = tmp & 0xFF
3972 } else if (placeHolders === 1) {
3973 tmp = (revLookup[b64.charCodeAt(i)] << 10) | (revLookup[b64.charCodeAt(i + 1)] << 4) | (revLookup[b64.charCodeAt(i + 2)] >> 2)
3974 arr[L++] = (tmp >> 8) & 0xFF
3975 arr[L++] = tmp & 0xFF
3976 }
3977
3978 return arr
3979}
3980
3981function tripletToBase64 (num) {
3982 return lookup[num >> 18 & 0x3F] + lookup[num >> 12 & 0x3F] + lookup[num >> 6 & 0x3F] + lookup[num & 0x3F]

Callers

nothing calls this directly

Calls 1

placeHoldersCountFunction · 0.70

Tested by

no test coverage detected