Skip to content

Instantly share code, notes, and snippets.

@prakashsvmx
Created May 20, 2021 09:26
Show Gist options
  • Save prakashsvmx/192960edbe8488c5704be4a63912d767 to your computer and use it in GitHub Desktop.
Save prakashsvmx/192960edbe8488c5704be4a63912d767 to your computer and use it in GitHub Desktop.
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);
})
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment