Thanks! So it sounds like this would be preferred.

https://gist.github.com/anonymous/5273601


On Fri, Mar 29, 2013 at 3:38 PM, Andrew Hart <hartandr...@gmail.com> wrote:

> On Friday, March 29, 2013 1:55:36 PM UTC-6, Mark Volkmann wrote:
>
>> Is this the recommended way to read from a Readable stream in 0.10?
>>
>> I can only share what I've discovered.
>
>
>> Can I assume that I will always get a 'readable" event when the stream is
>> ready to be read?
>>
>> Can I assume I will get a new 'readable' event after every call to
>> rs.read unless the end of the stream was reached?
>>
>> http://nodejs.org/api/stream.html#stream_readable_read_size_1
> If there is no data to consume, or if there are fewer bytes in the
> internal buffer than the size argument, thennull is returned, and a
> future 'readable' event will be emitted when more is available.
>
> I don't think the documentation allows you to assume a new readable event
> if read did not return null. That's consistent with my experiments as well.
>
>
>> Is it better to do something like this inside the 'readable' callback to
>> continue calling read until it returns null?
>>
>>   while (true) {
>>     var chunk = rs.read();
>>     if (!chunk) break;
>>     // do something with chunk
>>   }
>>
>> I think you need to specifically check for null. Otherwise, the stream
> might return the empty string or, if it is an "objectMode" stream (useful,
> but only mentioned in passing here:
> http://nodejs.org/api/stream.html#stream_new_stream_readable_optionsreading 
> the source suggests objectMode works fine for writable, transform,
> and duplex streams as well.), some other falsey value.
>
> Andrew Hart
>
> --
> --
> 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 nodejs@googlegroups.com
> To unsubscribe from this group, send email to
> nodejs+unsubscr...@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+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>



-- 
R. Mark Volkmann
Object Computing, Inc.

-- 
-- 
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 nodejs@googlegroups.com
To unsubscribe from this group, send email to
nodejs+unsubscr...@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+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to