Live data from Hacker News

Node.js stream handbook

github.com

11–18 of 18 posts

Re: Node.js stream handbook

#11
post #8

Not hoping to start any sort of flame war, but could someone try to explain this difference between streams and promises? The conceptual difference doesn't seem completely clear to me.

With streams you don't wait for them to end. They may never end, in fact.

Which is unlike Promises, which guarantee a single "end," but also don't care when that ends (could have already happened, could happen eventually). Seems similar in nature to a socket connection.

Re: Node.js stream handbook

#12
post #10

Not hoping to start any sort of flame war, but could someone try to explain this difference between streams and promises? The conceptual difference doesn't seem completely clear to me.

You may be interested in going through "A General Theory of Reactivity"[0] from Kris Kowal, creator of the q promise library. It discusses relationships between streams, promises, iterators and generators (although the streams that he discusses are not how Node.js streams are implemented) [0]: https://github.com/kriskowal/gtor

Cool, I'll have to take some time to read through more of that, but a quick skim actually made clear to me some of the differences I was missing, especially when combined with the other comments.

Re: Node.js stream handbook

#14

Not hoping to start any sort of flame war, but could someone try to explain this difference between streams and promises? The conceptual difference doesn't seem completely clear to me.

Basically a promise represents a single (future) value whereas a stream represents zero or more (ordered, future) values.

A queue of promises would be similar to a stream.

Re: Node.js stream handbook

#15
post #2

This is a great write-up on streams. For curiosity sake, I'd be interested to know the overhead of var stream = fs.createReadStream(__dirname + '/data.txt'); stream.pipe(res); vs. fs.readFile('./data.txt) and res(). and if streams become a better and better option as response sizes get larger and larger. The streams syntax is nicer looking in any case.

In addition to the other responses, the pipe version will get initial chunks of data across the HTTP connection sooner, so that the user starts seeing data on their screen.

Re: Node.js stream handbook

#16
Will it work with LIVE video streaming?

For example, can you use ffmpeg to pull live video via rtsp, re-encode and pipe to nodejs for it to stream down to browser and to be consumed by html - with or without a plugin?

Any working code sample?

Re: Node.js stream handbook

#18
post #16

Will it work with LIVE video streaming? For example, can you use ffmpeg to pull live video via rtsp, re-encode and pipe to nodejs for it to stream down to browser and to be consumed by html - with or without a plugin? Any working code sample?

Yup, it does. I do have a quick working example, with a plain multipart form :) You can check it out here: https://github.com/gabipurcaru/peggy

While this is not exactly what you are talking about, I think it demonstrates that node.js streams can do that too.

Post reply on HN