pass-through stream which can filter/adapt and pause data as it passes through (streams2)
pass-stream is a pass-through stream which allows transform fns for easily filtering or adapting the data that flows through the stream.
It is a light wrapper over Dominic Tarr's pause-stream which provides built-in buffering capabilities for pausing.
npm install pass-stream
passStream(writeFn, endFn)takes an optional writeFn and endFn and returns a pauseable stream which can be piped or used like any other
var passStream = require'pass-stream';var ps = passStream; // constructing stream without any transformationsreadStreampipepspipeanotherStream
To add transform/filter functionality you may provide a writeFn and/or endFn which allows you to tap into the write and end processing.
If you provide a writeFn, then it is up to you to call
this.queueWrite(data) with whatever transformed data.
If you provide a endFn, then it is up to you to call
this.queueEnd() when you are ready to end the stream (be sure this is after you are done with all your writes).
this context of the writeFn and endFn is set to that of the stream so you have all the normal stream functions like
resume. Note: you will not want to call
end from within these functions since they will cause a recursive loop.
var passStream = require'pass-stream';var length = 0;// we are assuming data is stringsthisqueueWritedatatoUpperCase; // upper caselength += datalength; // keep track of lengththisemit'length' length; // emit length now that it is donethisqueueEnd;var lengthResult = 0;var rstream = ;rstreampipepassStreamwriteFn endFn // construct a passStream with transformFnson'length' lengthResult = len;pipeanotherStream;
I could not find a through stream implementation which met all my expectations, so I wrote light wrapper around the best pausing pass-through stream I could find (dominictarr/pause-stream).
If you have input or ideas or would like to get involved, you may: