class FecReader {
constructor(reader, encoding) {
this._rows = [];
this._reader = reader;
this._decoder = new TextDecoder(encoding);
this._parser = fecParser().on("data", row => this._rows.push(row));
}
[Symbol.asyncIterator]() {
return this;
}
async next() {
const {done, value} = await this._reader.read();
const rows = this._rows;
if (done) {
if (rows) {
this._parser.end();
this._rows = null;
if (rows.length) return {done: false, value: rows};
}
return {done: true, value: undefined};
}
this._parser.write(this._decoder.decode(value, {stream: true}));
this._rows = [];
return {done: false, value: rows};
}
}