{"ScriptPreparationCode":"var ab = new ArrayBuffer(70*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 expected = window.btoa(String.fromCharCode.apply(null, 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 uint6ToB64(nUint6) {\r\n return nUint6 \u003C 26 ?\r\n nUint6 \u002B 65\r\n : nUint6 \u003C 52 ?\r\n nUint6 \u002B 71\r\n : nUint6 \u003C 62 ?\r\n nUint6 - 4\r\n : nUint6 === 62 ?\r\n 43\r\n : nUint6 === 63 ?\r\n 47\r\n :\r\n 65;\r\n};\r\n\r\nfunction bytesToBase64(aBytes) {\r\n var eqLen = (3 - (aBytes.length % 3)) % 3, sB64Enc = \u0022\u0022;\r\n\r\n for (var nMod3, nLen = aBytes.length, nUint24 = 0, nIdx = 0; nIdx \u003C nLen; nIdx\u002B\u002B) {\r\n nMod3 = nIdx % 3;\r\n nUint24 |= aBytes[nIdx] \u003C\u003C (16 \u003E\u003E\u003E nMod3 \u0026 24);\r\n if (nMod3 === 2 || aBytes.length - nIdx === 1) {\r\n sB64Enc \u002B= String.fromCharCode(uint6ToB64(nUint24 \u003E\u003E\u003E 18 \u0026 63), uint6ToB64(nUint24 \u003E\u003E\u003E 12 \u0026 63), uint6ToB64(nUint24 \u003E\u003E\u003E 6 \u0026 63), uint6ToB64(nUint24 \u0026 63));\r\n nUint24 = 0;\r\n }\r\n }\r\n\r\n return eqLen === 0 ?\r\n sB64Enc\r\n :\r\n sB64Enc.substring(0, sB64Enc.length - eqLen) \u002B (eqLen === 1 ? \u0022=\u0022 : \u0022==\u0022);\r\n};\r\n","TestCases":[{"Name":"String.fromCharCode.apply","Code":"var bin = String.fromCharCode.apply(null, uint8);\r\nvar res = window.btoa(bin)\r\nvalidate(res)","IsDeferred":false},{"Name":"byteArrayToString","Code":"var bin = byteArrayToString(uint8);\r\nvar res = window.btoa(bin)\r\nvalidate(res)","IsDeferred":false},{"Name":"superhuman","Code":"var res = B64.encode(uint8);\r\nvalidate(res)","IsDeferred":false}]}