MCPcopy Create free account
hub / github.com/Exrick/xpay / b64ToByteArray

Function b64ToByteArray

xpay-code/src/main/resources/static/swagger/swagger-ui.js:9634–9678  ·  view source on GitHub ↗
(b64)

Source from the content-addressed store, hash-verified

9632 }
9633
9634 function b64ToByteArray (b64) {
9635 var i, j, l, tmp, placeHolders, arr
9636
9637 if (b64.length % 4 > 0) {
9638 throw new Error('Invalid string. Length must be a multiple of 4')
9639 }
9640
9641 // the number of equal signs (place holders)
9642 // if there are two placeholders, than the two characters before it
9643 // represent one byte
9644 // if there is only one, then the three characters before it represent 2 bytes
9645 // this is just a cheap hack to not do indexOf twice
9646 var len = b64.length
9647 placeHolders = '=' === b64.charAt(len - 2) ? 2 : '=' === b64.charAt(len - 1) ? 1 : 0
9648
9649 // base64 is 4/3 + up to two characters of the original data
9650 arr = new Arr(b64.length * 3 / 4 - placeHolders)
9651
9652 // if there are placeholders, only get up to the last complete 4 chars
9653 l = placeHolders > 0 ? b64.length - 4 : b64.length
9654
9655 var L = 0
9656
9657 function push (v) {
9658 arr[L++] = v
9659 }
9660
9661 for (i = 0, j = 0; i < l; i += 4, j += 3) {
9662 tmp = (decode(b64.charAt(i)) << 18) | (decode(b64.charAt(i + 1)) << 12) | (decode(b64.charAt(i + 2)) << 6) | decode(b64.charAt(i + 3))
9663 push((tmp & 0xFF0000) >> 16)
9664 push((tmp & 0xFF00) >> 8)
9665 push(tmp & 0xFF)
9666 }
9667
9668 if (placeHolders === 2) {
9669 tmp = (decode(b64.charAt(i)) << 2) | (decode(b64.charAt(i + 1)) >> 4)
9670 push(tmp & 0xFF)
9671 } else if (placeHolders === 1) {
9672 tmp = (decode(b64.charAt(i)) << 10) | (decode(b64.charAt(i + 1)) << 4) | (decode(b64.charAt(i + 2)) >> 2)
9673 push((tmp >> 8) & 0xFF)
9674 push(tmp & 0xFF)
9675 }
9676
9677 return arr
9678 }
9679
9680 function uint8ToBase64 (uint8) {
9681 var i,

Callers

nothing calls this directly

Calls 2

pushFunction · 0.85
decodeFunction · 0.70

Tested by

no test coverage detected