Skip to content

Instantly share code, notes, and snippets.

@americanstone
Last active October 17, 2017 15:49
Show Gist options
  • Save americanstone/6e72da492cc7444c10dd63bac7dffd48 to your computer and use it in GitHub Desktop.
Save americanstone/6e72da492cc7444c10dd63bac7dffd48 to your computer and use it in GitHub Desktop.
getResponseSize from url
async function getResponseSize(url) {
const response = await fetch(url);
const reader = response.body.getReader();
let result = await reader.read();
let total = 0;
while (!result.done) {
const value = result.value;
total += value.length;
console.log('Received chunk', value);
// get the next result
result = await reader.read();
}
return total;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment