I'm trying to read large file (3GB) as slice as 100Mb.
***function sliceMe() {
var file = document.getElementById('files').files[0],
fr = new FileReader;
var chunkSize = document.getElementById('txtSize').value;
chunkSize =1048576;
var chunks = Math.ceil(file.size / chunkSize);
var chunk = 0;
document.getElementById('byte_range').innerHTML = "";
function loadNext() {
var start, end,
blobSlice = File.prototype.mozSlice || File.prototype.webkitSlice;
start = chunk * chunkSize;
if (start > file.size)
start = end+1;
end = start + (chunkSize -1) >= file.size ? file.size : start + (chunkSize -1);
fr.onload = function(e) {
if (++chunk <= chunks) {
document.getElementById('byte_range').innerHTML += chunk + " " +
['Read bytes: ', start , ' - ', end,
' of ', file.size, ' byte file'].join('')+"
";
//console.info(chunk);
loadNext(); // shortcut here
}
};
fr.readAsArrayBuffer(blobSlice.call(file, start, end));
}
loadNext();
}***
Above code works as expected in Firefox and in Chrome 16. But in Chrome 17 & 18dev version, after reading 1GB data browser crashes.
Is it known issue in Chrome 17?
解决方案
I had the same problem reading in a 1.8 GB file. If I watch task manager, chrome.exe would take up to 1.5 GB of memory and then crash. My solution was to use a Javascript worker and then use FileReaderSync instead of FileReader. The javascript worker runs in a separate thread, and FileReaderSync will only work in a javascript worker.