react / wstein / node_modules / browserify / node_modules / buffer / node_modules / base64-js / lib / b64.js
80542 viewsvar lookup = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';12;(function (exports) {3'use strict';45var Arr = (typeof Uint8Array !== 'undefined')6? Uint8Array7: Array89var PLUS = '+'.charCodeAt(0)10var SLASH = '/'.charCodeAt(0)11var NUMBER = '0'.charCodeAt(0)12var LOWER = 'a'.charCodeAt(0)13var UPPER = 'A'.charCodeAt(0)14var PLUS_URL_SAFE = '-'.charCodeAt(0)15var SLASH_URL_SAFE = '_'.charCodeAt(0)1617function decode (elt) {18var code = elt.charCodeAt(0)19if (code === PLUS ||20code === PLUS_URL_SAFE)21return 62 // '+'22if (code === SLASH ||23code === SLASH_URL_SAFE)24return 63 // '/'25if (code < NUMBER)26return -1 //no match27if (code < NUMBER + 10)28return code - NUMBER + 26 + 2629if (code < UPPER + 26)30return code - UPPER31if (code < LOWER + 26)32return code - LOWER + 2633}3435function b64ToByteArray (b64) {36var i, j, l, tmp, placeHolders, arr3738if (b64.length % 4 > 0) {39throw new Error('Invalid string. Length must be a multiple of 4')40}4142// the number of equal signs (place holders)43// if there are two placeholders, than the two characters before it44// represent one byte45// if there is only one, then the three characters before it represent 2 bytes46// this is just a cheap hack to not do indexOf twice47var len = b64.length48placeHolders = '=' === b64.charAt(len - 2) ? 2 : '=' === b64.charAt(len - 1) ? 1 : 04950// base64 is 4/3 + up to two characters of the original data51arr = new Arr(b64.length * 3 / 4 - placeHolders)5253// if there are placeholders, only get up to the last complete 4 chars54l = placeHolders > 0 ? b64.length - 4 : b64.length5556var L = 05758function push (v) {59arr[L++] = v60}6162for (i = 0, j = 0; i < l; i += 4, j += 3) {63tmp = (decode(b64.charAt(i)) << 18) | (decode(b64.charAt(i + 1)) << 12) | (decode(b64.charAt(i + 2)) << 6) | decode(b64.charAt(i + 3))64push((tmp & 0xFF0000) >> 16)65push((tmp & 0xFF00) >> 8)66push(tmp & 0xFF)67}6869if (placeHolders === 2) {70tmp = (decode(b64.charAt(i)) << 2) | (decode(b64.charAt(i + 1)) >> 4)71push(tmp & 0xFF)72} else if (placeHolders === 1) {73tmp = (decode(b64.charAt(i)) << 10) | (decode(b64.charAt(i + 1)) << 4) | (decode(b64.charAt(i + 2)) >> 2)74push((tmp >> 8) & 0xFF)75push(tmp & 0xFF)76}7778return arr79}8081function uint8ToBase64 (uint8) {82var i,83extraBytes = uint8.length % 3, // if we have 1 byte left, pad 2 bytes84output = "",85temp, length8687function encode (num) {88return lookup.charAt(num)89}9091function tripletToBase64 (num) {92return encode(num >> 18 & 0x3F) + encode(num >> 12 & 0x3F) + encode(num >> 6 & 0x3F) + encode(num & 0x3F)93}9495// go through the array every three bytes, we'll deal with trailing stuff later96for (i = 0, length = uint8.length - extraBytes; i < length; i += 3) {97temp = (uint8[i] << 16) + (uint8[i + 1] << 8) + (uint8[i + 2])98output += tripletToBase64(temp)99}100101// pad the end with zeros, but make sure to not forget the extra bytes102switch (extraBytes) {103case 1:104temp = uint8[uint8.length - 1]105output += encode(temp >> 2)106output += encode((temp << 4) & 0x3F)107output += '=='108break109case 2:110temp = (uint8[uint8.length - 2] << 8) + (uint8[uint8.length - 1])111output += encode(temp >> 10)112output += encode((temp >> 4) & 0x3F)113output += encode((temp << 2) & 0x3F)114output += '='115break116}117118return output119}120121exports.toByteArray = b64ToByteArray122exports.fromByteArray = uint8ToBase64123}(typeof exports === 'undefined' ? (this.base64js = {}) : exports))124125126