Node.js。如何将多个流(数组或链)传递到管道中?
Node.js. How to pass a several streams (array or chain) into pipe?
我有一个返回多个流的函数:
// function
var s1 = through.obj({highWaterMark: 2}, function(data, enc, next) {
console.log( "A: "+data );
next(null, "A");
});
var s2 = through.obj({highWaterMark: 2}, function(data, enc, next) {
console.log( "B: "+data );
next(null, "B");
});
return [s1, s2];
// or chain:
// s1.pipe(s2);
// return s1;
我想将函数的结果传递给管道:
gulp.src(...).pipe(...).pipe( getStreams() ).pipe(gulp.dest...);
有办法吗?
或者也许我可以像下一个那样做?
var s1 = getStreams();
gulp.src(...).pipe(...).pipe( s1 )
s1.getLastStreamOfChain().pipe(gulp.dest...);
您可以使用 merge-stream
模块:
const mergeStream = require('merge-stream');
gulp.src(...).pipe(...).pipe(mergeStream(s1, s2)).pipe(gulp.dest...);
我找到了一些方法来做到这一点。
1)
s1.pipe(s2);
s1.lastStreamOfChain = s2;
stream.pipe(s1).lastStreamOfChain.pipe(s3); // Of course it is not good
2)
使用stream-combiner2.
combine.obj(s1, s2);
is there any way to reuse a chain of pipe transformations in NodeJS?
我有一个返回多个流的函数:
// function
var s1 = through.obj({highWaterMark: 2}, function(data, enc, next) {
console.log( "A: "+data );
next(null, "A");
});
var s2 = through.obj({highWaterMark: 2}, function(data, enc, next) {
console.log( "B: "+data );
next(null, "B");
});
return [s1, s2];
// or chain:
// s1.pipe(s2);
// return s1;
我想将函数的结果传递给管道:
gulp.src(...).pipe(...).pipe( getStreams() ).pipe(gulp.dest...);
有办法吗?
或者也许我可以像下一个那样做?
var s1 = getStreams();
gulp.src(...).pipe(...).pipe( s1 )
s1.getLastStreamOfChain().pipe(gulp.dest...);
您可以使用 merge-stream
模块:
const mergeStream = require('merge-stream');
gulp.src(...).pipe(...).pipe(mergeStream(s1, s2)).pipe(gulp.dest...);
我找到了一些方法来做到这一点。 1)
s1.pipe(s2);
s1.lastStreamOfChain = s2;
stream.pipe(s1).lastStreamOfChain.pipe(s3); // Of course it is not good
2) 使用stream-combiner2.
combine.obj(s1, s2);
is there any way to reuse a chain of pipe transformations in NodeJS?