Created
May 16, 2019 15:48
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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