Advertisement
Guest User

Untitled

a guest
Jul 29th, 2017
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.44 KB | None | 0 0
  1. async function getResponseSize(url) {
  2. const response = await fetch(url);
  3. const reader = response.body.getReader();
  4. let total = 0;
  5.  
  6. while (true) {
  7. const {done, value} = await reader.read();
  8. if (done) return total;
  9. total += value.length;
  10. }
  11. }
  12.  
  13. async function getResponseSize(url) {
  14. const response = await fetch(url);
  15. let total = 0;
  16.  
  17. for await (const chunk of response.body) {
  18. total += chunk.length;
  19. }
  20. return total;
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement