javascript - nodejs stream pipe into already piped N streams -
i want pipe 1 stream n piped streams, code below returns here2
doesn't go in first transform stream. seems piped streams doesn't behave 1 stream.
'use strict'; var stream = require('stream'); var through2 = require('through2'); var pass = new stream.passthrough({objectmode: true}); var transform1 = through2.obj(function(obj, enc, done) { console.log('here1'); this.push(obj); done(); }).pipe(through2.obj(function(obj, enc, done) { console.log('here2'); this.push(obj); done(); })); pass.write({'hello': 'world'}); pass.pipe(transform1).on('data', function(data) { console.log(data); });
the pipe
method returns destination stream. transform1
stream 2nd stream in pipe chain. writing pass
stream 2nd stream (hence output 'here 2'): try this:
pass.pipe(through2.obj(function(obj, enc, done) { console.log('here1'); this.push(obj); done(); })).pipe(through2.obj(function(obj, enc, done) { console.log('here2'); this.push(obj); done(); })); pass.write({'hello': 'world'});
Comments
Post a Comment