title: Calculate AJAX download speed
body: <p>I would like to display the download speed in real time as a file is downloaded, however the following code is not working. <code>Speed</code> returns 0.0 for the entire download.</p>
  
  <pre><code>https.get(options, function (update) {
      fileSize = (parseInt(update.headers['content-length']) / 1048576).toFixed(1);
      startTime = (new Date()).getTime();
      endTime = startTime;
      update.on('data', function (chunk) {
          file.write(chunk);
          len += chunk.length;
          fileDownloaded = (len / 1048576).toFixed(1);
          endTime = (new Date()).getTime();
          time = (endTime - startTime) / 1000;
          speed = ((fileSize / time) / (1024 * 1024)).toFixed(2);
          progressPercentage.html(fileDownloaded + ' MB / ' + fileSize + ' MB ' + speed + ' MB/s');
      });
  });
  </code></pre>