Published
Edited
Oct 11, 2018
2 forks
14 stars
Insert cell
Insert cell
mutable progress = 0
Insert cell
result = {
const response = await fetch(url);

// Check if streaming is supported.
const reader = response.body && response.body.getReader();
if (!reader) {
const value = new Uint8Array(await response.arrayBuffer());
mutable progress = value.length;
return value;
}

// Read chunks, updating as we go.
const values = [];
mutable progress = 0;
while (true) {
const {done, value} = await reader.read();
if (done) break;
mutable progress += value.length;
values.push(value);
}

// Concatenate chunks into an array.
return concat(Uint8Array, values);
}
Insert cell
function concat(type, arrays) {
let i = 0;
let n = 0;
for (const a of arrays) n += a.length;
const concat = new type(n);
for (let a of arrays) concat.set(a, i), i += a.length;
return concat;
}
Insert cell
url = "https://raw.githubusercontent.com/matplotlib/basemap/v1.1.0/lib/mpl_toolkits/basemap/data/UScounties.shp"
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