{"ScriptPreparationCode":"var ab = new ArrayBuffer(50*1024);\r\nvar uint8 = new Uint8Array(ab);\r\nfor (var i = 0; i \u003C ab.byteLength; i\u002B\u002B) {\r\n uint8[i] = i % 256;\r\n}\r\nvar b64 = btoa(uint8)\r\nvar json = JSON.stringify([...uint8]);\r\n\r\nfunction byteArrayToString(bytes) {\r\n var CHUNK_SIZE = 8*1024;\r\n if (bytes.length \u003C= CHUNK_SIZE)\r\n return String.fromCharCode.apply(null, bytes);\r\n var str = \u0027\u0027;\r\n for (var i = 0; i \u003C bytes.length; i \u002B= CHUNK_SIZE)\r\n str \u002B= String.fromCharCode.apply(null, bytes.slice(i, i\u002BCHUNK_SIZE));\r\n return str;\r\n}\r\n\r\nfunction validate(res){\r\n if (res !== expected)\r\n throw \u0022expected=\u0022 \u002B expected \u002B \u0022 but got \u0022 \u002B res;\r\n}\r\n\r\n\r\nfunction typedArrayFrom(base64_string) {\r\n return Uint8Array.from(atob(base64_string), c =\u003E c.charCodeAt(0))\r\n}\r\n\r\nfunction jsonParse(jsonStr) {\r\n return Uint8Array.from(JSON.parse(jsonStr))\r\n}\r\n\r\nvar chars = \u0022ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789\u002B/\u0022;\r\n\r\n// Use a lookup table to find the index.\r\nvar lookup = new Uint8Array(256);\r\nfor (var i = 0; i \u003C chars.length; i\u002B\u002B) {\r\n lookup[chars.charCodeAt(i)] = i;\r\n}\r\n\r\nvar niklasvh = function(base64) {\r\n var bufferLength = base64.length * 0.75,\r\n len = base64.length, i, p = 0,\r\n encoded1, encoded2, encoded3, encoded4;\r\n\r\n if (base64[base64.length - 1] === \u0022=\u0022) {\r\n bufferLength--;\r\n if (base64[base64.length - 2] === \u0022=\u0022) {\r\n bufferLength--;\r\n }\r\n }\r\n\r\n var arraybuffer = new ArrayBuffer(bufferLength),\r\n bytes = new Uint8Array(arraybuffer);\r\n\r\n for (i = 0; i \u003C len; i\u002B=4) {\r\n encoded1 = lookup[base64.charCodeAt(i)];\r\n encoded2 = lookup[base64.charCodeAt(i\u002B1)];\r\n encoded3 = lookup[base64.charCodeAt(i\u002B2)];\r\n encoded4 = lookup[base64.charCodeAt(i\u002B3)];\r\n\r\n bytes[p\u002B\u002B] = (encoded1 \u003C\u003C 2) | (encoded2 \u003E\u003E 4);\r\n bytes[p\u002B\u002B] = ((encoded2 \u0026 15) \u003C\u003C 4) | (encoded3 \u003E\u003E 2);\r\n bytes[p\u002B\u002B] = ((encoded3 \u0026 3) \u003C\u003C 6) | (encoded4 \u0026 63);\r\n }\r\n\r\n return arraybuffer;\r\n};\r\n\r\nvar danguer = {\r\n\t_keyStr : \u0022ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789\u002B/=\u0022,\r\n\t\r\n\t/* will return a Uint8Array type */\r\n\tdecodeArrayBuffer: function(input) {\r\n\t\tvar bytes = (input.length/4) * 3;\r\n\t\tvar ab = new ArrayBuffer(bytes);\r\n\t\tthis.decode(input, ab);\r\n\t\t\r\n\t\treturn ab;\r\n\t},\r\n\r\n\tremovePaddingChars: function(input){\r\n\t\tvar lkey = this._keyStr.indexOf(input.charAt(input.length - 1));\r\n\t\tif(lkey == 64){\r\n\t\t\treturn input.substring(0,input.length - 1);\r\n\t\t}\r\n\t\treturn input;\r\n\t},\r\n\r\n\tdecode: function (input, arrayBuffer) {\r\n\t\t//get last chars to see if are valid\r\n\t\tinput = this.removePaddingChars(input);\r\n\t\tinput = this.removePaddingChars(input);\r\n\r\n\t\tvar bytes = parseInt((input.length / 4) * 3, 10);\r\n\t\t\r\n\t\tvar uarray;\r\n\t\tvar chr1, chr2, chr3;\r\n\t\tvar enc1, enc2, enc3, enc4;\r\n\t\tvar i = 0;\r\n\t\tvar j = 0;\r\n\t\t\r\n\t\tif (arrayBuffer)\r\n\t\t\tuarray = new Uint8Array(arrayBuffer);\r\n\t\telse\r\n\t\t\tuarray = new Uint8Array(bytes);\r\n\t\t\r\n\t\tinput = input.replace(/[^A-Za-z0-9\\\u002B\\/\\=]/g, \u0022\u0022);\r\n\t\t\r\n\t\tfor (i=0; i\u003Cbytes; i\u002B=3) {\t\r\n\t\t\t//get the 3 octects in 4 ascii chars\r\n\t\t\tenc1 = this._keyStr.indexOf(input.charAt(j\u002B\u002B));\r\n\t\t\tenc2 = this._keyStr.indexOf(input.charAt(j\u002B\u002B));\r\n\t\t\tenc3 = this._keyStr.indexOf(input.charAt(j\u002B\u002B));\r\n\t\t\tenc4 = this._keyStr.indexOf(input.charAt(j\u002B\u002B));\r\n\t\r\n\t\t\tchr1 = (enc1 \u003C\u003C 2) | (enc2 \u003E\u003E 4);\r\n\t\t\tchr2 = ((enc2 \u0026 15) \u003C\u003C 4) | (enc3 \u003E\u003E 2);\r\n\t\t\tchr3 = ((enc3 \u0026 3) \u003C\u003C 6) | enc4;\r\n\t\r\n\t\t\tuarray[i] = chr1;\t\t\t\r\n\t\t\tif (enc3 != 64) uarray[i\u002B1] = chr2;\r\n\t\t\tif (enc4 != 64) uarray[i\u002B2] = chr3;\r\n\t\t}\r\n\t\r\n\t\treturn uarray;\t\r\n\t}\r\n}","TestCases":[{"Name":"jsonParse","Code":"jsonParse(json)","IsDeferred":false},{"Name":"danguer","Code":"danguer.decodeArrayBuffer(b64)","IsDeferred":false},{"Name":"niklasvh","Code":"niklasvh(b64)","IsDeferred":false},{"Name":"typedArrayFrom","Code":"typedArrayFrom(b64)","IsDeferred":false}]}