All files / utils httpProgressMiddleware.js

37.5% Statements 3/8
0% Branches 0/2
33.33% Functions 1/3
37.5% Lines 3/8
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18      12x 12x 12x                        
/* @flow */
 
export default function httpProgressMiddleware(req: any) {
  let loaded = 0;
  let total = 0;
  req.on("response", res => {
    if (total === 0) {
      total = res.headers["content-length"];
    }
 
    res.on("data", function(data) {
      loaded += data.length;
 
      req.emit("progress", { direction: "download", loaded: loaded, total: total });
    });
  });
}