stream-splicer icon indicating copy to clipboard operation
stream-splicer copied to clipboard

splice(index, howMany) doesn't pipe the remaining streams correctly, splice(index, howMany, through) does

Open mixu opened this issue 9 years ago • 1 comments

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

mixu avatar Sep 23 '14 21:09 mixu

+1

asafyish avatar Mar 28 '15 06:03 asafyish