How to read local binary file to UInt8Array fast. in below code
function readAllBytesAsUInt8Array(path) {
var req = new XMLHttpRequest();
req.open("GET", path, false);
req.overrideMimeType("text/plain; charset=binary-data");
req.send(null);
if (req.status !== 200) {
console.log("error");
return null;
}
var text = req.responseText;
var resultArray = new Uint8Array(text.length);
for(var i = 0; i < text.length;i++){
resultArray[i] = (text[i].charCodeAt() & 255) & 255;
}
return resultArray.buffer;
}
var text = req.responseText;
is executed less than a second,meanwhile this part
var resultArray = new Uint8Array(text.length);
for(var i = 0; i < text.length;i++){
resultArray[i] = (text[i].charCodeAt() & 255) & 255;
}
takes around 10sec for 50MB of binary file, Is there a way to read binary file to UInt8Array faster ?