Leonidas-from-XIV/node-xml2js — pull request #153 by asselin (2014-08-03 23:11:55+00:00)
Title: Make the options.async option parse the XML in chunks using setImmediate...

... to avoid blocking

I know this diff is against the generated xml2js.js file, but I'm not a coffee scripter, so I'm submitting what I'm able to.

Reason for this change:

My use case is to parse a very large XML file (~36MB). Before this change, the parser would block during parsing, and parsing that 36MB file would block node for approx 60 sec. With this change, options.async makes xml2js break the string up into chunks (by default 10000 bytes each, controllable with options.chunkSize), parse 1 chunk, and then call setImmediate to parse more. This eliminates the blocking, even on large XML files.

I also changed the this.on("end" and this.on("error" to not check the async flag. If the async flag is set, they will always be called asynchronously because of the setImmediate().

Sorry I couldn't do this on the original coffeescript, but I hope you will add this to the library.

Let me know if you have any questions/comments.