有没有办法在 NodeJS 中重用管道转换链?
问题描述:
例如如果我有
readableStream.pipe(ws1).pipe(ws2).pipe(ws3)
如何将转换链封装在单个函数中,然后在另一个转换链中重复使用?
How can I envelope that transformation chain in a single function and then reuse it in another transformation chain?
我想做这样的事情:
var transformationChain1 = readableStream.pipe(ws1).pipe(ws2).pipe(ws3)
readableStream2.pipe(transformationChain1).pipe(endWs)
答
你可能会用到
var combine = require('stream-combiner2')
var ws = combine(ws1, ws2, ws3);
readableStream2.pipe(ws).pipe(endWs);