Conditionally return a stream
$ npm install --save if-stream
const csvParser = require('csv-parser');
const ifStream = require('if-stream');
const isCsv = data => data.toString().indexOf(',') !== -1;
const stream = ifStream(isCsv, csvParser);
stream.on('data', data => {
console.log(data);
//=> {foo: 'bar', unicorn: 'cat'}
});
stream.end('foo,unicorn\nbar,cat\n');
Type: function, string, boolean, regex
Condition to match the stream buffer against.
Type: stream
The stream to be returned if the condition is met.
Type: stream
An optional stream to be returned if the condition isn't met. By default a transform stream is returned.
Type: object
Options to pass to peek-stream.
MIT © Kevin Martensson