Published
Edited
Mar 28, 2022
Importers
29 stars
Insert cell
Insert cell
viewof buffer = fetchProgress("https://raw.githubusercontent.com/datadesk/cpi/d582252c644b90d48918a4cba951baf3c03c9629/cpi/cpi.db", {mode: "cors"})
Insert cell
new Uint8Array(buffer)
Insert cell
function fetchProgress(url, init, max) {
const form = htl.html`<form><progress value=0>`;
const progress = form.firstChild;
if (max !== undefined) progress.max = max;
fetch(url, init).then(async response => {
if (max === undefined) progress.max = max = +response.headers.get("content-length");
const reader = response.body && response.body.getReader();
if (!reader) {
const value = await response.arrayBuffer();
progress.max = progress.value = value.byteLength;
form.value = value;
form.dispatchEvent(new CustomEvent("input"));
return value;
}
const values = [];
while (true) {
const {done, value} = await reader.read();
if (done) break;
progress.value += value.length;
values.push(value);
}
form.value = concat(values);
form.dispatchEvent(new CustomEvent("input"));
});
return form;
}
Insert cell
function concat(arrays) {
let i = 0;
let n = 0;
for (const a of arrays) n += a.length;
const concat = new Uint8Array(n);
for (let a of arrays) concat.set(a, i), i += a.length;
return concat.buffer;
}
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