Skip to content

Instantly share code, notes, and snippets.

@lovasoa
Created May 16, 2019 15:48
Show Gist options
  • Save lovasoa/b0454e02c343515f9de7272d337c79c1 to your computer and use it in GitHub Desktop.
Save lovasoa/b0454e02c343515f9de7272d337c79c1 to your computer and use it in GitHub Desktop.
fetch chunks: use the fetch and WHATWG Stream APIs to return an async generator of typed arrays given an URL
async function* fetchChunks(...args) {
let response = await fetch(...args);
let reader = response.body.getReader(), state = {done:false};
while (!state.done) {
state = await reader.read();
yield state.value;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment