Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Message from discussion Stream tweaks proposal
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Isaac Schlueter  
View profile  
 More options Jul 30 2012, 1:02 pm
From: Isaac Schlueter <i...@izs.me>
Date: Mon, 30 Jul 2012 10:02:12 -0700
Local: Mon, Jul 30 2012 1:02 pm
Subject: Re: [node-dev] Stream tweaks proposal

> there is another thing this would break, it would be impossible to
> stream a .read() based ReadableStream to multiple destinations...

Yeah, that use case is going to be hard.  If you want a tee-stream,
you can implement it pretty easily on top of this.  And of course, if
you use the "data" event facade, then it'll keep working just how it
does, so I don't expect existing programs to be affected too badly
until they specifically try to upgrade.

But, yes, this is a thing that's going to break in 0.9, most likely,
and someone probably will be affected by it.  The best approach is to
do it as soon as possible and document the changes.

On Sun, Jul 29, 2012 at 10:51 AM, Bruno Jouhier <bjouh...@gmail.com> wrote:
> Given this, I probably favor the callback style a lot more than most node
> developers.

For several implementations, a read(n, cb) method is easier to do.
For example, on Windows, that's how we read from sockets, and on all
platforms, that's how fs.read works.  So, we *must* implement
something like this for fs read streams anyway, and if we want elegant
cross-platform support, then we'll have to do that for TCP and Pipes
as well.

The ReadableStream base class will have a read([n]) method that
returns either up-to-n bytes (or some arbitrary number of bytes if n
is unspecified), or null.  If it returns null, then you wait for a
'readable' event and try again.

It will also have a _read(n, function(er, bytes)) method that you can
override with your own implementation details.  The assumption here is
that: n is always specified, the cb is called at some point in the
future with an error or up-to-n bytes.  The ReadableStream class will
take care of managing the buffer and calling this._read when
appropriate.  If there are no more bytes to read, then _read(n, cb)
should call the cb with null.

This makes it easy to interface with underlying systems that can only
do asynchronous reads, while still getting the benefits of the simpler
read(n)/emit('readable') API.

Of course, if your system CAN safely do reads synchronously (ie, if
it's some kind of abstract stream that reads from memory and doesn't
have to do any slow IO) then you can just override the read(n) method
instead of the _read(n, cb) method.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.