Skip to content

Instantly share code, notes, and snippets.

@gaogao-9
Last active July 21, 2016 07:40
Show Gist options
  • Save gaogao-9/67acd7263b8798ed502004acbd24f59d to your computer and use it in GitHub Desktop.
Save gaogao-9/67acd7263b8798ed502004acbd24f59d to your computer and use it in GitHub Desktop.
function consume(reader, length) {
var total = 0;
return (function pump() {
console.log(`${total} / ${length}`);
return reader.read().then(function(args) {
if (!args.done) {
total += args.value.byteLength;
return pump();
}
});
})();
};
fetch('/path/to').then(function(response) {
var length = +response.headers.get('Content-Length');
var reader = response.body.getReader();
return consume(reader, length);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment