【发布时间】:2012-12-18 04:57:06
【问题描述】:
我想将 HTTP 响应的内容流式传输到变量。我的目标是通过request() 获取图像,并将其存储在 MongoDB 中 - 但图像总是损坏。
这是我的代码:
request('http://google.com/doodle.png', function (error, response, body) {
image = new Buffer(body, 'binary');
db.images.insert({ filename: 'google.png', imgData: image}, function (err) {
// handle errors etc.
});
})
在这种情况下使用 Buffer/streams 的最佳方式是什么?
【问题讨论】: