nested.js 882 B

123456789101112131415161718192021222324252627282930313233343536
  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 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. [ split(), addNewLines ],
  14. through(function (buf, enc, next) {
  15. this.push('> ' + buf);
  16. next()
  17. })
  18. ]);
  19. stream.get(0).unshift(through(function (buf, enc, next) {
  20. this.push(buf.toString('utf8').toUpperCase());
  21. next();
  22. }));
  23. stream.pipe(concat(function (body) {
  24. t.deepEqual(body.toString(), '> A\n> B\n> C\n');
  25. }));
  26. stream.write('a\n');
  27. stream.write('b\n');
  28. stream.write('c');
  29. stream.end();
  30. });