1/* 2 * Base64URL-ArrayBuffer 3 * https://github.com/herrjemand/Base64URL-ArrayBuffer 4 * 5 * Copyright (c) 2017 Yuriy Ackermann <[email protected]> 6 * Copyright (c) 2012 Niklas von Hertzen 7 * Licensed under the MIT license. 8 * 9 */ 10(function(){ 11 "use strict"; 12 13 var chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"; 14 15 // Use a lookup table to find the index. 16 var lookup = new Uint8Array(256); 17 for (var i = 0; i < chars.length; i++) { 18 lookup[chars.charCodeAt(i)] = i; 19 } 20 21 var encode = function(arraybuffer) { 22 var bytes = new Uint8Array(arraybuffer), 23 i, len = bytes.length, base64 = ""; 24 25 for (i = 0; i < len; i+=3) { 26 base64 += chars[bytes[i] >> 2]; 27 base64 += chars[((bytes[i] & 3) << 4) | (bytes[i + 1] >> 4)]; 28 base64 += chars[((bytes[i + 1] & 15) << 2) | (bytes[i + 2] >> 6)]; 29 base64 += chars[bytes[i + 2] & 63]; 30 } 31 32 if ((len % 3) === 2) { 33 base64 = base64.substring(0, base64.length - 1); 34 } else if (len % 3 === 1) { 35 base64 = base64.substring(0, base64.length - 2); 36 } 37 38 return base64; 39 }; 40 41 var decode = function(base64) { 42 var bufferLength = base64.length * 0.75, 43 len = base64.length, i, p = 0, 44 encoded1, encoded2, encoded3, encoded4; 45 46 var arraybuffer = new ArrayBuffer(bufferLength), 47 bytes = new Uint8Array(arraybuffer); 48 49 for (i = 0; i < len; i+=4) { 50 encoded1 = lookup[base64.charCodeAt(i)]; 51 encoded2 = lookup[base64.charCodeAt(i+1)]; 52 encoded3 = lookup[base64.charCodeAt(i+2)]; 53 encoded4 = lookup[base64.charCodeAt(i+3)]; 54 55 bytes[p++] = (encoded1 << 2) | (encoded2 >> 4); 56 bytes[p++] = ((encoded2 & 15) << 4) | (encoded3 >> 2); 57 bytes[p++] = ((encoded3 & 3) << 6) | (encoded4 & 63); 58 } 59 60 return arraybuffer; 61 }; 62 63 /** 64 * Exporting and stuff 65 */ 66 if (typeof module !== 'undefined' && typeof module.exports !== 'undefined') { 67 module.exports = { 68 'encode': encode, 69 'decode': decode 70 } 71 72 } else { 73 if (typeof define === 'function' && define.amd) { 74 define([], function() { 75 return { 76 'encode': encode, 77 'decode': decode 78 } 79 }); 80 } else { 81 window.base64url = { 82 'encode': encode, 83 'decode': decode 84 } 85 } 86 } 87})();
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.