stream.Transform events

56 views
Skip to first unread message

Ruud

unread,
Apr 13, 2013, 5:01:33 PM4/13/13
to nod...@googlegroups.com
Hey,

I'm trying to create a streaming parser/transformer for a special web proxy project. The 'streams2' stream.Transform base class makes this quite easy, but trying to benchmark some thing I've hit a problem: it seems no (end) events are emitted.

The docs don't list any events under this class explicitly, but one would imagine the events from the stream.Readable and stream.Writable are also implemented in stream.Transform.

My question: Am I doing something wrong, is this by design, or could this be considered a bug?

Al I could find on the subject is this Stack Overflow question + comment

Code (more or less):
stream = require('stream');
function Parser (options) {
if (!(this instanceof Parser)) return new Parser(options);
stream.Transform.call(this, options);
this.options = options || {};
}
util.inherits(Parser, stream.Transform);
Parser.prototype._transform = function(chunk, encoding, done) {
// magic stuff that transforms chunk
this.push(chunk);
done();
};

parser = new Parser();
parser.on('end', function () {
console.log('This will never happen ???');
});
req.pipe(parser, {end: false}).pipe(res);



Dan Milon

unread,
Apr 13, 2013, 7:59:31 PM4/13/13
to nod...@googlegroups.com
You're explicitly asking it not to emit an end event by passing end: false to pipe. 
--
--
Job Board: http://jobs.nodejs.org/
Posting guidelines: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to nod...@googlegroups.com
To unsubscribe from this group, send email to
nodejs+un...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en
 
---
You received this message because you are subscribed to the Google Groups "nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nodejs+un...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Ruud

unread,
Apr 13, 2013, 9:08:15 PM4/13/13
to nod...@googlegroups.com
Okay, now I feel stupid. Thank you for your response. I was able to test and confirm that the stream.Transform and Passtrough DO emit an end event (and all other relevant events).
Not sure yet what is wrong with my application code, but I'll find out tomorrow.

I think that the code in the SO answer misses a call to `done` in the Uppercase._transform tough, so that might be a reason stuff went wrong (I might have used that as a base for the test)
Reply all
Reply to author
Forward
0 new messages