0

I am currently trying to write a tool to browse and look for certain nodes in a local 900+ MB XML file by using Just Google Chrome and Javascript. As there is no way to directly access local files, i set up a file Input Element, that i read with the FileReader API, just to parse it to XML afterwards.

When reading the file, Chrome crashes because the RAM limit has been reached. This seems to be a limitation implemented by the Browser, because the Ram limit of my Computer isn't reached by far. This is my code:

let xmlFile = "";
let fileInput = document.getElementById('fileInput');
let fileReader = new FileReader();
let readProgress = document.getElementById('readProgress');

fileInput.addEventListener('change', readFile);

function readFile(){
    let f = fileInput.files[0];
    fileReader.readAsText(f);

}

fileReader.onload = function(event){
    xmlFile = $.parseXML(event.target.result);
    console.log(xmlFile);
    console.log('done');
}


fileReader.onprogress = function(event){
    let percent;
    percent = event.loaded/event.total*100;
    readProgress.textContent = percent;
}

Is there any way to increase the Chrome RAM limit, or are there any better ways to handle an XML file this big?

Thanks in Advance

Barneo

Barneo
  • 1
  • 1
  • _"As there is no way to directly access local files"_ Local files can be directly accessed at Chrome, Chromium. Launch Chrome, Chromium with `--allow-file-access-from-files` flag set. See [Read local XML with JS](https://stackoverflow.com/questions/41279589/read-local-xml-with-js). Have you filed a [bug](https://bugs.chromium.org/p/chromium/issues/list) relevant to `Blob` limitations? – guest271314 Jul 13 '17 at 13:58
  • How much `RAM` is installed at computer you tried JavaScript at? – guest271314 Jul 13 '17 at 14:08
  • Is your OS 32-bit or 64-bit? –  Jul 13 '17 at 14:14
  • You're trying to read the whole file into memory at once which is bad for anyone using your tool since it most likely will crash the browser. Instead of calling `fileReader.readAsText` you could read the blob itself by slice into memory and then process it in chunks. Check this SO question: https://stackoverflow.com/questions/25810051/filereader-api-on-big-files – Khauri Jul 13 '17 at 14:28
  • What occurs when you try to load the file using `file:` protocol `file:///path/to/file/at/local/filesystem` at browser address field? What is application? How is `xmlFile` used after `load` event of `FileReader`? – guest271314 Jul 13 '17 at 14:33
  • See https://bugs.chromium.org/p/chromium/issues/detail?id=375297&can=1&q=Blob%20RAM&colspec=ID%20Pri%20M%20Stars%20ReleaseBlock%20Component%20Status%20Owner%20Summary%20OS%20Modified – guest271314 Jul 13 '17 at 15:07
  • I have 8GB RAM installed on a 64-Bit Windows OS – Barneo Jul 17 '17 at 09:40

0 Answers0