{"ScriptPreparationCode":"var typedArray, blob;\r\n\r\ntypedArray = new Uint8Array(1024 * 1024);\r\nfor (var i = 0; i \u003C typedArray.length; typedArray[i] = i % 256, \u002B\u002Bi);\r\n\r\nblob = new Blob([typedArray], {type: \u0027application/octet-binary\u0027}); \r\n\r\nfunction computeHash_direct(file, hashCallback, errorCallback) {\r\n var hashAlgo = new sha1asm();\r\n var hash;\r\n\r\n // function parseFile(file, endCallback) {\r\n var fileSize = file.size,\r\n chunkSize = 2097152, // 1024 * 1024 * 2 - read in chunks of 2MB\r\n offset = 0,\r\n endByte,\r\n time,\r\n fileReader = new FileReader();\r\n\r\n function readNextChunk() {\r\n var endFromOffset = offset \u002B chunkSize,\r\n endByte = endFromOffset \u003E= fileSize ? fileSize : endFromOffset;\r\n fileReader.readAsArrayBuffer(file.slice(offset, endByte));\r\n }\r\n\r\n fileReader.onloadend = function (e) {\r\n var arrayBuffer = e.target.result;\r\n\r\n hashAlgo.update(new Uint8Array(arrayBuffer));\r\n \r\n offset \u002B= arrayBuffer.byteLength;\r\n if (offset \u003C fileSize) {\r\n readNextChunk();\r\n } else {\r\n hash = hashAlgo.final();\r\n // console.log(\u0022Time to parse (direct) (ms): \u0022 \u002B (new Date().getTime() - time));\r\n // console.log(\u0022Hash (sha1asm): \u0022 \u002B hash);\r\n if (!e.target.error) {\r\n hashCallback(hash);\r\n } else {\r\n errorCallback(e.target.error);\r\n }\r\n //endCallback(e.target.error);\r\n }\r\n\r\n };\r\n fileReader.onerror = function () {\r\n };\r\n\r\n time = new Date().getTime();\r\n hashAlgo.reset();\r\n readNextChunk();\r\n}\r\n\r\nfunction computeHash_parse(file, hashCallback, errorCallback) {\r\n var hashAlgo;\r\n\r\n function parseFile(file, chunkCallback, endCallback) {\r\n var // blobSlice = File.prototype.slice || File.prototype.mozSlice || File.prototype.webkitSlice,\r\n fileSize = file.size,\r\n chunkSize = 2097152, // 1024 * 1024 * 2 - read in chunks of 2MB\r\n offset = 0,\r\n endByte,\r\n time,\r\n fileReader = new FileReader();\r\n\r\n function readNextChunk() {\r\n var endFromOffset = offset \u002B chunkSize,\r\n endByte = endFromOffset \u003E= fileSize ? fileSize : endFromOffset;\r\n //fileReader.readAsArrayBuffer(blobSlice.call(file, offset, endByte));\r\n fileReader.readAsArrayBuffer(file.slice(offset, endByte));\r\n }\r\n\r\n fileReader.onloadend = function (e) {\r\n var arrayBuffer = e.target.result;\r\n\r\n chunkCallback(arrayBuffer);\r\n\r\n offset \u002B= arrayBuffer.byteLength;\r\n if (offset \u003C fileSize) {\r\n readNextChunk();\r\n } else {\r\n endCallback(e.target.error);\r\n //console.log(\u0022Time to parse (parse) (ms): \u0022 \u002B (new Date().getTime() - time));\r\n }\r\n };\r\n fileReader.onerror = function () {\r\n // running = false;\r\n // registerLog(\u0027\u003Cstrong\u003EOops, something went wrong.\u003C/strong\u003E\u0027, \u0027error\u0027);\r\n };\r\n\r\n time = new Date().getTime();\r\n readNextChunk();\r\n }\r\n\r\n hashAlgo = new sha1asm();\r\n hashAlgo.reset();\r\n parseFile(file,\r\n function (arrayBuffer) {\r\n hashAlgo.update(new Uint8Array(arrayBuffer));\r\n // hashAlgo.update(arrayBuffer);\r\n },\r\n function (err) {\r\n if (! err) {\r\n var hash = hashAlgo.final();\r\n // console.log(\u0022Hash (sha1asm): \u0022 \u002B hash);\r\n hashCallback(hash);\r\n } else if (typeof errorCallback === \u0022function\u0022 ) {\r\n errorCallback(err);\r\n }\r\n \t\t\t}\r\n );\r\n} \r\n\r\nfunction logHash(hash) {\r\n // console.log(\u0022Hash:\u0022, hash);\r\n}\r\n\r\nfunction logErr(err) {\r\n // console.log(\u0022ERROR:\u0022, err);\r\n}\r\n","TestCases":[{"Name":"computeHash_direct","Code":"computeHash_direct(blob, logHash, logErr);","IsDeferred":false},{"Name":"computeHash_parse","Code":"computeHash_parse(blob, logHash, logErr);","IsDeferred":false}]}