Published
Edited
Dec 2, 2019
2 stars
Insert cell
Insert cell
fecParser = require("fec-parse@0.22")
Insert cell
url = FileAttachment("1358932.fec").url()
Insert cell
{
const response = await fetch(url);
const reader = response.body.getReader();
for await (const rows of new FecReader(reader)) {
yield* rows;
}
}
Insert cell
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};
}
}
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more