我希望以一种简洁的方式对流进行条件性处理,这里所说的行为是指:
if (someBoolean) {
stream = fs
.createReadStream(filepath)
.pipe(decodeStream(someOptions))
.pipe(writeStream);
} else {
stream = fs
.createReadStream(filepath)
.pipe(writeStream);
}
我已经准备好了所有流,如果
someBoolean
是 true,我想要将另一个流添加到管道中。然后我尝试使用 detour-stream 解决问题,但不幸的是没有成功设置。我使用类似于 gulp-if 的符号表示方法,因为这被提及为灵感来源:
var detour = require('detour-stream');
stream = fs
.createReadStream(filepath)
.detour(someBoolean, decodeStream(someOptions))
.pipe(writeStream);
但是,不幸的是,这只会导致一个错误:
.detour(someBoolean, decodeStream(someOptions))
^
TypeError: undefined is not a function
有什么想法吗?