node-xml icon indicating copy to clipboard operation
node-xml copied to clipboard

parseFile reads the entire file

Open wampleek opened this issue 13 years ago • 2 comments

I think the primary reason to use a Sax parser is concern about doc size. Should this module consider file streaming instead of a full read? As written, I suspect there is only a 2-4x memory savings over building the document in memory.

wampleek avatar Jun 24 '11 20:06 wampleek

Yeah, this is really bad. The code should be like this:

var s = fs.ReadStream(filename);
s.on('data', function(d) {
    parser.parseString(d, false);
});
s.on('end', function() {
    parser.parseString('', true);
});

See also issue #21 where you should be able to say when the input has ended.

JasonWoof avatar Oct 06 '11 20:10 JasonWoof

+1

marook avatar Apr 29 '13 15:04 marook