【发布时间】:2019-11-14 10:29:02
【问题描述】:
我正在使用request 模块来获取一个包含 70K 行的大型 CSV 文件。
但是,正文中只显示了约 500 行。
代码如下:
request({
url: "https://somedomain.com/path/to/file.csv",
method: "GET"
} , function (error, response, body) {
if (error)
console.error(error);
else if(body && util.isString(body)){
let dataArr = body.split("\n");
console.log(dataArr.length);//Expected 70K, actual ~500
}
});
我想我需要使用某种类似于这样的流:
request('http://google.com/doodle.png').pipe(fs.createWriteStream('doodle.png'));
但是,我不需要将其保存到磁盘,我正在使用它来构建 MongoDB 查询,例如:
let mongoQuery = {username: {$in:dataArr}}//dataArr should include 70K elements, each element is a string containing up to 60 chars.
有人能指出我正确的方向吗?
【问题讨论】:
标签: node.js node-request