Splice multiple streams into a single pipeline. Useful for exposing multi-step piped streams as a single stream.
Compose multi-step streams into a single pipeline segment.
E.g. your transform module is actually two consecutive transform operations, but you want it exposed as a single "stream.Transform" object.
// In your modulemoduleexports = txvar filter = require"through2-filter"var map = require"through2-map"var splice = require"stream-splice"var noBs = filter return /[^bB]/execchunkvar uc = map return chunktoStringtoUpperCasevar zz = map return chunktoString + "z"return splicenoBs uc zz// Using your module:var tx = require"my-module"sourcepipetxpipe/* ... */// That is equivalent to:sourcepipenoBspipeucpipezzpipe/* ... */// A less contrived example:// catLines is equivalent to fs.createReadStream except stream chunks// will be the lines of the filemoduleexports = catLinesvar fs = require"fs"var split = require"split"var map = require"through2-map"var splice = require"stream-splice"var rs = fscreateReadStreamfilename optionsvar reAddNewline = map return chunktoString + "\n"return splicers split reAddNewline
Creates a pipeline that can be piped into/out of which is composed of all of the spliced streams piped together.
sourcepipesplicea b cpipedrain// is roughly equivalent tosourcepipeapipebpipecpipedrain
splice does NOT attempt to do error forwarding. Sure, it could do something where all the errors in the pipeline are forwarded onto the topmost stream, however this would create a hidden requirement of code organization where your error handlers would have to be above the
splice call to avoid double-handled errors.
So do this:
aon"error" someErrHandlerbon"error" someErrHandlercon"error" someErrHandlersourcepipesplicea b cpipedrain
This will let you keep the maximum flexibility with your error handling.