Repositorio del curso CCOM4030 el semestre B91 del proyecto Paz para la Mujer

through.js 733B

123456789101112131415161718192021222324252627282930313233343536
  1. var test = require('tape');
  2. var resumer = require('../');
  3. var concat = require('concat-stream');
  4. test('through write/end', function (t) {
  5. t.plan(2);
  6. var s = createStream();
  7. s.on('okok', function () {
  8. t.ok(true);
  9. });
  10. s.pipe(concat(function (err, body) {
  11. t.equal(body, 'BEGIN\nRAWR\nEND\n');
  12. }));
  13. setTimeout(function () {
  14. s.end('rawr\n');
  15. }, 50);
  16. });
  17. function createStream () {
  18. var stream = resumer(write, end);
  19. stream.queue('BEGIN\n');
  20. return stream;
  21. function write (x) {
  22. this.queue(String(x).toUpperCase());
  23. }
  24. function end () {
  25. this.emit('okok');
  26. this.queue('END\n');
  27. this.queue(null);
  28. }
  29. }