Skip to content

Instantly share code, notes, and snippets.

@renaatdemuynck
Last active November 25, 2019 12:24
Show Gist options
  • Save renaatdemuynck/744ffc2459cd7a0e9d82e166f3ea4dd9 to your computer and use it in GitHub Desktop.
Save renaatdemuynck/744ffc2459cd7a0e9d82e166f3ea4dd9 to your computer and use it in GitHub Desktop.
fetch('http://localhost/my-script.js').then(response => {
var reader = response.body.getReader();
var result = new Uint8Array();
reader.read().then(function processText({ done, value }) {
if (done) {
let decoder = new TextDecoder('utf-8');
return decoder.decode(result);
}
let temp = new Uint8Array(result.length + value.length);
temp.set(result);
temp.set(value, result.length);
result = temp;
return reader.read().then(processText);
}).then(console.log);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment