Assuming you're sticking with the pipe() method for connecting streams 
(which you probably should), there are a few methods for telling when a 
stream is "done".

The error event will disconnect the pipe and it will throw the error unless 
there is another error listener to catch it. The error event does NOT call 
end() so you can decide what to do about the state of the stream at that 
point. 

The end event signals that the stream has been stopped, this could be from 
a pipe or some other code execution. It could mean there's no more data, or 
it was manually stopped.

The close event fires on socket streams it signals that the socket has been 
closed and the pipe() method will then call destroy on the socket. It is 
unusable after this.

In order to orchestrate stream control flow properly, you'll have to watch 
for these various events and do the right thing. The important thing to 
note is that you should create all of your input streams at once, because 
the data will either be lost (because you're not ready to pipe them all) or 
you'll have to buffer it into memory. You want to wait until the previous 
input stream ends, then call create the next one and pipe it.

Most of this info is from some personal experience but mostly from reading 
the pipe source code. It's simple and gives a clear picture of what happens 
when you pipe.

https://github.com/joyent/node/blob/master/lib/stream.js

:Marco

-- 
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

Reply via email to