一直觉得stream是node.js的利器,有了这么方便而且强大的东西,node.js在处理数据的能力上如虎添翼。。。。
能够将stream封转的这么简单也算是不容易了。。。
直接上代码:
http.get("http://a.xnimg.cn/imgpro/login/phone-show.jpg", function(res) {
res.pipe(fs.createWriteStream("aa.data"));
res.on('end', function(){
console.log("close");
});
}).on('error', function(e) {
console.log("Got error: " + e.message);
});