我有一条小溪,但我想把它一分为二,一半放在一个目的地,另一半放在另一个目的。
我的想法是,我需要将流分叉两次,过滤每个新流,在每个流上使用gulp.dest
,然后将它们合并回来,并将它们返回以吞咽。
我现在有代码,
function dumpCpuProfiles(profileDirectory) {
const _ = require('highland');
const stream = _();
const cpuProfiles = stream
.fork()
.pipe(filter('*.cpuprofile'))
.pipe(gulp.dest(profileDirectory));
const noCpuProfiles = _(cpuProfiles).filter(() => false);
const otherFiles = stream
.fork()
.pipe(filter(['**', '!**/*.cpuprofile']));
return _([noCpuProfiles, otherFiles]).merge();
}
然而,我得到了错误,
TypeError: src.pull is not a function
at /home/user/project/node_modules/highland/lib/index.js:3493:17
at Array.forEach (native)
at pullFromAllSources (/home/user/project/node_modules/highland/lib/index.js:3492:15)
at Stream._generator (/home/user/project/node_modules/highland/lib/index.js:3449:13)
at Stream._runGenerator (/home/user/project/node_modules/highland/lib/index.js:949:10)
at Stream.resume (/home/user/project/node_modules/highland/lib/index.js:811:22)
at Stream._checkBackPressure (/home/user/project/node_modules/highland/lib/index.js:713:17)
at Stream.resume (/home/user/project/node_modules/highland/lib/index.js:806:29)
at Stream.pipe (/home/user/project/node_modules/highland/lib/index.js:895:7)
at Gulp.<anonymous> (/home/user/project/gulpfile.js:189:6)
输出是流,所以我不太确定错误是怎么回事。任何帮助都会非常有用!谢谢
我使用这个小的猴痘匹配技巧来实现
Object.prototype.fork = function(_fn) {
_fn(this);
return this;
};
Stream是唯一的事件发射器,管道方法不会返回旧的流,而是返回一个新的流,所以您可以非常容易地构建fork功能。