You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
exportclassJSONParserextendsstream.Transform{lastLineData='';constructor(){super({objectMode: true});}_transform(chunk: any,encoding: string,cb: Function){letdata=String(chunk);if(this.lastLineData){data=this.lastLineData+data;}letlines=data.split('\n');this.lastLineData=lines.splice(lines.length-1,1)[0];lines.forEach(l=>{try{// l might be an empty string; ignore if sol&&this.push(JSON.parse(l));}catch(err){// noop}});cb();}_flush(cb: Function){if(this.lastLineData){try{this.push(JSON.parse(this.lastLineData));}catch(err){// noop}}this.lastLineData='';cb();}}
that seems to work, but what would be nice is something like this:
exportclassJSONParserextendsstream.Transform{lastLineData='';staticoptions={objectMode: true};// <<< options are same for all instancesconstructor(){super();}_transform(chunk: any,encoding: string,cb: Function){letdata=String(chunk);if(this.lastLineData){data=this.lastLineData+data;}letlines=data.split('\n');this.lastLineData=lines.splice(lines.length-1,1)[0];lines.forEach(l=>{try{// l might be an empty string; ignore if sol&&this.push(JSON.parse(l));}catch(err){// noop}});cb();}_flush(cb: Function){if(this.lastLineData){try{this.push(JSON.parse(this.lastLineData));}catch(err){// noop}}this.lastLineData='';cb();}}
it could potentially be more performant, but not that sure if it's worth it.
The text was updated successfully, but these errors were encountered:
Given the lack of input from others and the fact that this is quite awkward to make work ergonomically, I don't think this is something that will actually get implemented in Node.js. That said, if you do want to see something like this the best way is to just do it yourself and open a PR — see where that goes. :) Do feel free to reopen if you feel strongly about this though.
Right now I have this:
that seems to work, but what would be nice is something like this:
it could potentially be more performant, but not that sure if it's worth it.
The text was updated successfully, but these errors were encountered: