UNPKG

etl

Version:

Collection of stream-based components that form an ETL pipeline

30 lines (24 loc) 742 B
const duplexer3 = require('duplexer3'); const Streamz = require('streamz'); const toStream = require('./tostream'); module.exports = function(fn) { const inStream = Streamz(); const outStream = Streamz(); if (fn.length > 1) fn(inStream,outStream); else toStream(fn(inStream)).pipe(outStream); const stream = duplexer3({objectMode: true},inStream,outStream); // Mirror error and promise behaviour from streamz stream.on('error',e => { if (stream._events.error.length < 2) { const pipes = stream._readableState.pipes; if (pipes) [].concat(pipes).forEach(child => child.emit('error',e)); else throw e; } }); stream.promise = Streamz.prototype.promise; return stream; };