Skip to content

Instantly share code, notes, and snippets.

@gskachkov
Created July 28, 2017 11:42
Show Gist options
  • Save gskachkov/6371147a916a9e6ae99cfab2ba29fba3 to your computer and use it in GitHub Desktop.
Save gskachkov/6371147a916a9e6ae99cfab2ba29fba3 to your computer and use it in GitHub Desktop.
async function getResponseSize(url) {
const response = await fetch(url);
const reader = response.body.getReader();
let total = 0;
while (true) {
const {done, value} = await reader.read();
if (done) return total;
total += value.length;
}
}
async function getResponseSize(url) {
const response = await fetch(url);
let total = 0;
for await (const chunk of response.body) {
total += chunk.length;
}
return total;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment