Created
April 4, 2019 16:05
-
-
Save korzio/9aa3d7519fea9db1eed59938578b6170 to your computer and use it in GitHub Desktop.
This file contains 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
function getResponseSize(url) { | |
return fetch(url).then(response => { | |
const reader = response.body.getReader() | |
let total = 0 | |
return reader.read().then(function processResult(result) { | |
if (result.done) return total | |
const value = result.value | |
total += value.length | |
console.log('Received chunk', value) | |
return reader.read().then(processResult) | |
}) | |
}) | |
} |
Author
korzio
commented
Apr 4, 2019
•
async function getResponseSizeAsync(url) {
const response = await fetch(url)
const reader = response.body.getReader()
let total = 0
while (true) {
const result = await reader.read()
if (result.done) {
return total
}
const value = result.value
total += value.length
console.log('Received chunk', value)
}
}
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment