react / wstein / node_modules / browserify / node_modules / http-browserify / node_modules / Base64 / base64.js
80542 views;(function () {12var object = typeof exports != 'undefined' ? exports : this; // #8: web workers3var chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';45function InvalidCharacterError(message) {6this.message = message;7}8InvalidCharacterError.prototype = new Error;9InvalidCharacterError.prototype.name = 'InvalidCharacterError';1011// encoder12// [https://gist.github.com/999166] by [https://github.com/nignag]13object.btoa || (14object.btoa = function (input) {15for (16// initialize result and counter17var block, charCode, idx = 0, map = chars, output = '';18// if the next input index does not exist:19// change the mapping table to "="20// check if d has no fractional digits21input.charAt(idx | 0) || (map = '=', idx % 1);22// "8 - idx % 1 * 8" generates the sequence 2, 4, 6, 823output += map.charAt(63 & block >> 8 - idx % 1 * 8)24) {25charCode = input.charCodeAt(idx += 3/4);26if (charCode > 0xFF) {27throw new InvalidCharacterError("'btoa' failed: The string to be encoded contains characters outside of the Latin1 range.");28}29block = block << 8 | charCode;30}31return output;32});3334// decoder35// [https://gist.github.com/1020396] by [https://github.com/atk]36object.atob || (37object.atob = function (input) {38input = input.replace(/=+$/, '');39if (input.length % 4 == 1) {40throw new InvalidCharacterError("'atob' failed: The string to be decoded is not correctly encoded.");41}42for (43// initialize result and counters44var bc = 0, bs, buffer, idx = 0, output = '';45// get next character46buffer = input.charAt(idx++);47// character found in table? initialize bit storage and add its ascii value;48~buffer && (bs = bc % 4 ? bs * 64 + buffer : buffer,49// and if not first of each 4 characters,50// convert the first 8 bits to one ascii character51bc++ % 4) ? output += String.fromCharCode(255 & bs >> (-2 * bc & 6)) : 052) {53// try to find character in table (0-63, not found => -1)54buffer = chars.indexOf(buffer);55}56return output;57});5859}());606162