Answer the question
In order to leave comments, you need to log in
How are streams rendered in node.js?
app.get('/stream', function(req, res) {
var stream = fs.createReadStream(__dirname + 'text.txt')
stream.pipe(res)
})
app.get('/image', function(req, res) {
var stream = fs.createReadStream(__dirname + 'image.png')
stream.pipe(res)
})
Answer the question
In order to leave comments, you need to log in
If you look at the vorpos a little wider, you can stumble upon information about MIME-types and server response headers. In short, not all formats support "streaming" data transfer. Basically, some video formats (MP4, MOV, etc.) and some audio formats (AAC, etc.) support this type. Pictures are usually transferred as a whole (as well as pdf), if there is no other implementation on the server.
These were general words, now on the issue. Thread, in nodejs, is an abstraction i.e. it does not mean that the data is being streamed. Behind the scene of `stream.pipe` is working with `data`, `end` and other events . Those. we get the stream, subscribe to `data` (read the data) and `end` (close the stream). A clearer example can be found here . It's better to read this book .where everything is detailed.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question