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

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more