读取远程文件的最佳方法是什么?我想获取整个文件(而不是块)。
我从下面的例子开始
var get = http.get(options).on('response', function (response) {
response.on('data', function (chunk) {
console.log('BODY: ' + chunk);
});
});
我想将文件解析为 csv,但是为此我需要整个文件而不是分块数据。
I'd use request https://github.com/mikeal/request为了这:
request('http://google.com/doodle.png').pipe(fs.createWriteStream('doodle.png'))
或者,如果您不需要先保存到文件,而只需将 CSV 读入内存,则可以执行以下操作:
var request = require('request');
request.get('http://www.whatever.com/my.csv', function (error, response, body) {
if (!error && response.statusCode == 200) {
var csv = body;
// Continue with your processing here.
}
});
etc.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)