2014-10-06 55 views
1

例如,如果我有有什么方法可以在NodeJS中重复使用管道转换链吗?

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

我怎样才能信封变换链在一个单一的功能,然后再用它在另一个变换链?

我想要做一些这样的:

var transformationChain1 = readableStream.pipe(ws1).pipe(ws2).pipe(ws3) 
readableStream2.pipe(transformationChain1).pipe(endWs) 

回答

3

你很可能

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

是的杰罗姆,是的。谢谢 :) – Felo 2014-10-06 17:40:14

0

也许我误解(和我的Node.js是生锈所以这是完全可能的),但为什么不这样做,你说什么,敷在一个函数?

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

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

我的观点是,transformationChain的参数必须是readableStream2.pipe(),而不是一个新readableStream的结果。这对我也有点困惑。我想使用流合并器https://www.npmjs.org/package/stream-combiner,但也许我误解和复杂的事情。 :) – Felo 2014-10-06 17:10:14

+0

我想这是在我的头上,然后。也许它会帮助你画一个图,或者写一个更具体的例子? – 2014-10-06 17:13:45

相关问题