Tag: ndjson

如何在Node.js中closureshttpsstream

我正在通过https加载一个.ndjson文件。 我想在阅读100行文件后closures它。 const amount = 100; https.get(url, (res) => { var { statusCode } = res; if (statusCode !== 200) { throw new Error(`Request Failed.\n Status Code: ${statusCode}`); } res.setEncoding('utf8'); let rows = []; res .pipe(ndjson.parse()) .on('data', function (obj) { rows.push(obj); if (rows.length === amount) { this.end(); } }) .on('end', () => { resolve(rows); }); […]