Sto leggendo questo articolo: http://elegantcode.com/2011/04/06/taking-baby-steps-with-node-js-pumping-data-between-streams/ e ho alcuni problemi di comprensione dei flussi.nodejs streams vs callbacks
Citazione:
"Suppose we want to develop a simple web application that reads a particular file from disk and send it to the browser. The following code shows a very simple and naïve implementation in order to make this happen."
Così il codice di esempio è la seguente:
var readStream = fileSystem.createReadStream(filePath);
readStream.on('data', function(data) {
response.write(data);
});
readStream.on('end', function() {
response.end();
});
Perché dovremmo usare in questo modo al di sopra quando avremmo potuto semplicemente fare:
fs.readFile(filePath, function(err, data){
response.write(data);
response.end();
});
Quando o perché dovrei usare i flussi?