nested_middle.js 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. var pipeline = require('../');
  2. var through = require('through2');
  3. var split = require('split');
  4. var concat = require('concat-stream');
  5. var test = require('tape');
  6. test('nested middle splicer', function (t) {
  7. t.plan(1);
  8. var addNewLines = through(function (buf, enc, next) {
  9. this.push(buf + '\n');
  10. next();
  11. });
  12. var stream = pipeline.obj([
  13. through.obj(function (str, enc, next) {
  14. this.push(str.replace(/^./, function (c) {
  15. return String.fromCharCode(c.charCodeAt(0) + 5);
  16. }));
  17. next();
  18. }),
  19. [ split(), addNewLines ],
  20. through(function (buf, enc, next) {
  21. this.push('> ' + buf);
  22. next()
  23. })
  24. ]);
  25. stream.get(1).unshift(through(function (buf, enc, next) {
  26. this.push(buf.toString('utf8').toUpperCase());
  27. next();
  28. }));
  29. stream.pipe(concat(function (body) {
  30. t.deepEqual(body.toString(), '> F\n> G\n> H\n');
  31. }));
  32. stream.write('a\n');
  33. stream.write('b\n');
  34. stream.write('c');
  35. stream.end();
  36. });