在玩节点流时,我注意到几乎每个教程都教导如下:
// Get Google's home page. require('http').get("http://www.google.com/", function(response) { // The callback provides the response readable stream. // Then, we open our output text stream. var outStream = require('fs').createWriteStream("out.txt"); // Pipe the input to the output, which writes the file. response.pipe(outStream); });
但在我看来,这是一个非常危险的部分代码.如果文件流在某个点引发异常会发生什么?我认为文件流可能会泄漏内存,因为根据文档,文件流显然不是很接近.
我应该关心吗?在我的选项node.js流应该处理情况......