stream-splicer
stream-splicer copied to clipboard
splice(index, howMany) doesn't pipe the remaining streams correctly, splice(index, howMany, through) does
Based on how Array.splice works, I expected to be able to just call splice(index, howMany)
to remove an entry from the pipeline. However, if you don't pass a stream the splice fails to correctly call pipe on the remaining streams. Example case:
var through = require('through2'),
splicer = require('labeled-stream-splicer');
function log() {
return through.obj(function(o, enc, onDone) {
console.log(o);
this.push(o);
onDone();
});
}
console.log('splice(label, 1)');
var s1 = splicer.obj([
log(),
'foo', log(),
log()
]);
s1.splice('foo', 1);
s1.write('hello 1');
console.log('splice(label, 1, through)');
var s2 = splicer.obj([
log(),
'foo', log(),
log()
]);
s2.splice('foo', 1, through.obj());
s2.write('hello 2');
Output:
splice(label)
hello 1
splice(label, through)
hello 2
hello 2
+1