मैं इस लेख को पढ़ रहा हूं: http://elegantcode.com/2011/04/06/taking-baby-steps-with-node-js-pumping-data-between-streams/ और धाराओं को समझने में कुछ मामूली समस्याएं हैं।नोडज स्ट्रीम स्ट्रीम बनाम कॉलबैक
उद्धरण:
"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."
तो कोड नमूना इस प्रकार है के रूप में:
var readStream = fileSystem.createReadStream(filePath);
readStream.on('data', function(data) {
response.write(data);
});
readStream.on('end', function() {
response.end();
});
हम ऊपर तरीका है कि क्यों लूं जब हम बस कर सकता है:
fs.readFile(filePath, function(err, data){
response.write(data);
response.end();
});
मैं कब या क्यों स्ट्रीम का उपयोग करूंगा?