Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Something like a Broadcaster? #31

Open
mildsunrise opened this issue Jul 26, 2012 · 4 comments
Open

Something like a Broadcaster? #31

mildsunrise opened this issue Jul 26, 2012 · 4 comments

Comments

@mildsunrise
Copy link

I mean, an utility which gets a list of Writable streams as destinations,
then writes any data it recieves to every destination.

I run into this issue very often, especially when I want to stream some
live data into the client and record it in a file.

function streamLiveAudio(output) {
  // read audio from the device
  // and write it to "output".
}

http.createServer(function(req,res) {
  // write headers...

  var outfile = fs.createWriteStream('audio.raw', {flags: 'a'});
  var broadcaster = new Broadcaster(outfile, res);

  streamLiveAudio(broadcaster);
}).listen(3121);

It should also broadcast other events such as end.
This is the only utility I miss in Pipette. Excuse me if it's already present.

PD: Thumbs up, this is a _great module!_
I don't understand why it has so few watchers.

@danfuzz
Copy link
Contributor

danfuzz commented Jul 26, 2012

Thanks for the kudos, and thanks for the suggestion!

Up until now, I've mostly concentrated on the reader side of the equation, but that's only due to the happenstance of my particular needs. I've wondered if a any writer-side helpers might be of use to folks, and it looks like you have just such a case.

In terms of API of the constructed instance, I think what you're asking for is just to provide the standard Node writable stream interface. Is that correct? If so, that sounds totally reasonable to me.

As a matter of detail, I've settled on taking arrays for multiple streams rather than having them be separate arguments, because (a) it makes some use cases easier (that you'd otherwise need to resort to func.apply() to do), and (b) it also makes having an optional options argument a bit more straightforward (it'll always be in the same argument position).

What do you think?

@mildsunrise
Copy link
Author

In terms of API of the constructed instance, I think what you're asking for is just to provide the standard Node writable stream interface. Is that correct? If so, that sounds totally reasonable to me.

Exactly, follow the standard. :)
But it's just a suggestion.

About arrays vs dynamic arguments: I don't mind.
But when I said «list of Writable streams» I was thinking more about arrays.
And I agree with you that taking an array is better for a more consistent and straightforward API.

In fact, the standard Buffer.concat(...) does exactly that:
it takes an array of Buffers as first argument, and an options object as second argument.

@danfuzz
Copy link
Contributor

danfuzz commented Jul 26, 2012

I'm not sure how much time I'll be able to devote to this in the very short term (or rather, I probably won't have much), but I did a quick and as yet untested sketch in the branch danfuzz-write. If you're interested, check it out and poke at it.

@mildsunrise
Copy link
Author

Wow. The Tee class looks great!
I didn't think it was a sketch.
The code seems very elaborated.

Can't wait to test it!
I ♥ pipette (the name is fun)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants