Is there a way to reuse the pipe transform chain in NodeJS?

For example, if I have

readableStream.pipe(ws1).pipe(ws2).pipe(ws3)

How can I recoup this transformation chain into one function and then reuse it in another transformation chain?

I want to do the following:

var transformationChain1 = readableStream.pipe(ws1).pipe(ws2).pipe(ws3)
readableStream2.pipe(transformationChain1).pipe(endWs)
+1
source share
2 answers

you can probably use

var combine = require('stream-combiner2')
var ws = combine(ws1, ws2, ws3);
readableStream2.pipe(ws).pipe(endWs);
+3
source

Maybe I misunderstand (and my Node.js is rusty, so that’s quite possible), but why not do exactly what you said and wrap it in a function?

function transformationChain(rs) {
  return rs.pipe(ws1).pipe(ws2).pipe(ws3);
}

var transformationChain1 = transformationChain(readableStream);
readableStream2.pipe(transformationChain1).pipe(endWs);
0
source

All Articles