Last active
July 21, 2016 07:40
-
-
Save gaogao-9/67acd7263b8798ed502004acbd24f59d 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
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