diff --git a/README.md b/README.md index 016909f..436447a 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,3 @@ - # Xtreamer [![npm version][npm-image]][npm-url] @@ -115,7 +114,7 @@ xtreamerTransform.on("data", (data) => { }); ### max_xml_size ( default - 10000000 ) -`max_xml_size` is maximum the number of characters allowed to hold in memory. +`max_xml_size` is maximum the number of characters allowed to hold in memory. `xtreamer` raises an `error` event in case in memory xml string exceed specified limit. This ensures that the node process doesn't get terminated because of excess in memory data collection. @@ -145,6 +144,34 @@ Note that the converted JSON is internally stringified before sending it back to In case transformer function encounters an error, `xtreamer` emits `error` event and stops the xml conversion process. +## pass_all_nodes (default - false) + +`pass_all_nodes` defines whether to pass only matching nodes or all of them. + +This can be helpful when modifying an XML document on the fly without loosing non matching nodes. + +```javascript +const xtreamer = require("xtreamer"); +// Override `pass_all_nodes` +const options = { pass_all_nodes: true }; +const xtreamer = Xtreamer("XmlNode", options) +``` + +The receiving function must verify before processing, i.e. +```javascript +// A piped transformer +async _transform(chunk, enc, done) { + if (Buffer.isBuffer(chunk)) chunk = chunk.toString(); + if (!chunk.startsWith(" 0) { + this.push(otherNode); + nodes.push(otherNode); + } + } this._options && this._options.transformer && typeof this._options.transformer === "function" ? this.push(JSON.stringify(await this._options.transformer(xmlNode))) : this.push(xmlNode); @@ -52,4 +66,4 @@ module.exports = (node, options = { max_xml_size: Constants.MAX_XML_LENGTH }) => options = options || {}; options.max_xml_size = options.max_xml_size || Constants.MAX_XML_LENGTH; return new Xtreamer(node, options); -}; \ No newline at end of file +}; diff --git a/package.json b/package.json index 03553e2..d982302 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "xtreamer", - "version": "1.1.2", + "version": "1.1.3", "description": "A NodeJS package to read XML files using NodeJS streams.", "main": "lib/index.js", "scripts": {