I may have incorrect use of stream.Transform.
I piped one stream to my own transform object as source. And piped this
transform obejct to another stream as destination, depending on conditions.
Then I found that if I set no destination to this transform object, it
works really slow. Unfortrunatly, I need emit events during transform no
matter it pipes out or not.
Code:
StreamedSocketProtocol.prototype._transform = function(chunk, encoding,
done) {
this.buf.push(chunk);
function tryParser() {
// ...
}
// ...
var result;
while( result = tryParser(this.buf) ){ // buf may contain more than one
message, or simply not even one
this.emit('message', result); // good, found one
this.push(result); // output
}
// ...
this.buf.clear();
done();
}
//...
var transformStream = new StreamedSocketProtocol();
transformStream.on('message', function() {
// do something. But notice this may be very late
});
var sourceStream;
sourceStream.pipe(transformStream, {end: false});
// This is interesting, because if (somethingHappened == false) here,
// transformStream may not work for a long time
// That is, transform stream need a destnation or it may be very slow!
if(somethingHappened) {
var destinationStream;
transformStream.pipe(destinationStream, {end: false});
}
// To make transform stream keep up, what I do is to use null device
function createNullDevice () {
if (os.type().match(/(windows)/i)) {
return fs.createWriteStream('nul');
}else{
return fs.createWriteStream('/dev/null');
}
};
var nullDevice = createNullDevice ();
transformStream.pipe(nullDevice, {end: false});
I may have used Transform incorrectly, but someone may encounter this
problem again. And I do think Node.js needs a cross-platform null device.
--
--
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 [email protected]
To unsubscribe from this group, send email to
[email protected]
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 [email protected].
For more options, visit https://groups.google.com/groups/opt_out.