Last active
October 17, 2017 15:49
-
-
Save americanstone/6e72da492cc7444c10dd63bac7dffd48 to your computer and use it in GitHub Desktop.
getResponseSize from 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 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