有没有什么方法可以在NodeJS中重复使用一系列pipe道转换?

例如,如果我有

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

我怎样才能将这个转换链封装在一个函数中,然后在另一个转换链中重用呢?

我想要这样做:

 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); 

也许我误解了(和我的Node.js是生锈的,所以这是完全可能的),但为什么不完全按照你所说的,把它包装在一个函数?

 function transformationChain(rs) { return rs.pipe(ws1).pipe(ws2).pipe(ws3); } var transformationChain1 = transformationChain(readableStream); readableStream2.pipe(transformationChain1).pipe(endWs);