Created
July 28, 2017 11:42
-
-
Save gskachkov/6371147a916a9e6ae99cfab2ba29fba3 to your computer and use it in GitHub Desktop.
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 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