1/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ 2/* Base64 class: Base 64 encoding / decoding (c) Chris Veness 2002-2011 */ 3/* note: depends on Utf8 class */ 4/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ 5 6var Base64 = {}; // Base64 namespace 7 8Base64.code = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="; 9 10/** 11 * Encode string into Base64, as defined by RFC 4648 [http://tools.ietf.org/html/rfc4648] 12 * (instance method extending String object). As per RFC 4648, no newlines are added. 13 * 14 * @param {String} str The string to be encoded as base-64 15 * @param {Boolean} [utf8encode=false] Flag to indicate whether str is Unicode string to be encoded 16 * to UTF8 before conversion to base64; otherwise string is assumed to be 8-bit characters 17 * @returns {String} Base64-encoded string 18 */ 19Base64.encode = function(str, utf8encode) { // http://tools.ietf.org/html/rfc4648 20 utf8encode = (typeof utf8encode == 'undefined') ? false : utf8encode; 21 var o1, o2, o3, bits, h1, h2, h3, h4, e=[], pad = '', c, plain, coded; 22 var b64 = Base64.code; 23 24 plain = utf8encode ? Utf8.encode(str) : str; 25 26 c = plain.length % 3; // pad string to length of multiple of 3 27 if (c > 0) { while (c++ < 3) { pad += '='; plain += '\0'; } } 28 // note: doing padding here saves us doing special-case packing for trailing 1 or 2 chars 29 30 for (c=0; c<plain.length; c+=3) { // pack three octets into four hexets 31 o1 = plain.charCodeAt(c); 32 o2 = plain.charCodeAt(c+1); 33 o3 = plain.charCodeAt(c+2); 34 35 bits = o1<<16 | o2<<8 | o3; 36 37 h1 = bits>>18 & 0x3f; 38 h2 = bits>>12 & 0x3f; 39 h3 = bits>>6 & 0x3f; 40 h4 = bits & 0x3f; 41 42 // use hextets to index into code string 43 e[c/3] = b64.charAt(h1) + b64.charAt(h2) + b64.charAt(h3) + b64.charAt(h4); 44 } 45 coded = e.join(''); // join() is far faster than repeated string concatenation in IE 46 47 // replace 'A's from padded nulls with '='s 48 coded = coded.slice(0, coded.length-pad.length) + pad; 49 50 return coded; 51} 52 53/** 54 * Decode string from Base64, as defined by RFC 4648 [http://tools.ietf.org/html/rfc4648] 55 * (instance method extending String object). As per RFC 4648, newlines are not catered for. 56 * 57 * @param {String} str The string to be decoded from base-64 58 * @param {Boolean} [utf8decode=false] Flag to indicate whether str is Unicode string to be decoded 59 * from UTF8 after conversion from base64 60 * @returns {String} decoded string 61 */ 62Base64.decode = function(str, utf8decode) { 63 utf8decode = (typeof utf8decode == 'undefined') ? false : utf8decode; 64 var o1, o2, o3, h1, h2, h3, h4, bits, d=[], plain, coded; 65 var b64 = Base64.code; 66 67 coded = utf8decode ? Utf8.decode(str) : str; 68 69 for (var c=0; c<coded.length; c+=4) { // unpack four hexets into three octets 70 h1 = b64.indexOf(coded.charAt(c)); 71 h2 = b64.indexOf(coded.charAt(c+1)); 72 h3 = b64.indexOf(coded.charAt(c+2)); 73 h4 = b64.indexOf(coded.charAt(c+3)); 74 75 bits = h1<<18 | h2<<12 | h3<<6 | h4; 76 77 o1 = bits>>>16 & 0xff; 78 o2 = bits>>>8 & 0xff; 79 o3 = bits & 0xff; 80 81 d[c/4] = String.fromCharCode(o1, o2, o3); 82 // check for padding 83 if (h4 == 0x40) d[c/4] = String.fromCharCode(o1, o2); 84 if (h3 == 0x40) d[c/4] = String.fromCharCode(o1); 85 } 86 plain = d.join(''); // join() is far faster than repeated string concatenation in IE 87 88 return utf8decode ? Utf8.decode(plain) : plain; 89} 90 91/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.