【发布时间】:2013-12-25 06:56:28
【问题描述】:
在玩节点流时,我注意到几乎每个教程都教授以下内容:
// 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 流应该处理情况......
【问题讨论】:
标签: node.js http asynchronous stream pipe