最新消息: 电脑我帮您提供丰富的电脑知识,编程学习,软件下载,win7系统下载。

如何计算进度条中的恢复和暂停数据量

IT培训 admin 9浏览 0评论

如何计算进度条中的恢复和暂停数据量

暂停和恢复功能后,如何计算接收的数据。

我正在进行文件下载,包括下载暂停和恢复。

它暂停了,但是当我恢复它时,它不会达到100%。它在100%之前停止

  function download_file(event, filename) {
          req2 = request({
            method: 'GET',
            uri: fileURL
          });
            var out = fs.createWriteStream(finalPath);
            req2.pipe(out);
            req2.on('response', function(data) {
total_bytes = parseInt(data.headers['content-length']);
    progressBar.max = total_bytes;
    total_size = total_bytes;
            });
            req2.on('data', function(chunk) {
                    received_bytes += chunk.length;
 console.log(received_bytes);
progressBar.value = received_bytes;
display.innerText = Math.round((progressBar.value / progressBar.max) * 1000) / 10 + '%'
              }
            });
        };

    function pause22() {
      console.log('pause function called');
      req2.pause();
    }

        function resume22() {
          console.log('RESUME function called');
 progressBar.max=progressBar.max-progressBar.value;
  console.log(progressBar.max);
  console.log(progressBar.value);
   progressBar.value = received_bytes;
   received_bytes= progressBar.value;
  req2.resume();
        }
回答如下:

假设你想继续下载中断的地方,并且你将'total_bytes'和'received_bytes'存储为全局变量,那么你的进度条就会重新建立起来。你的简历22应该......

function resume22() {
      console.log('RESUME function called');
      progressBar.max=total_bytes;
      console.log(progressBar.max);
      progressBar.value = received_bytes;
      console.log(progressBar.value);
      req2.resume();
    }

如何计算进度条中的恢复和暂停数据量

暂停和恢复功能后,如何计算接收的数据。

我正在进行文件下载,包括下载暂停和恢复。

它暂停了,但是当我恢复它时,它不会达到100%。它在100%之前停止

  function download_file(event, filename) {
          req2 = request({
            method: 'GET',
            uri: fileURL
          });
            var out = fs.createWriteStream(finalPath);
            req2.pipe(out);
            req2.on('response', function(data) {
total_bytes = parseInt(data.headers['content-length']);
    progressBar.max = total_bytes;
    total_size = total_bytes;
            });
            req2.on('data', function(chunk) {
                    received_bytes += chunk.length;
 console.log(received_bytes);
progressBar.value = received_bytes;
display.innerText = Math.round((progressBar.value / progressBar.max) * 1000) / 10 + '%'
              }
            });
        };

    function pause22() {
      console.log('pause function called');
      req2.pause();
    }

        function resume22() {
          console.log('RESUME function called');
 progressBar.max=progressBar.max-progressBar.value;
  console.log(progressBar.max);
  console.log(progressBar.value);
   progressBar.value = received_bytes;
   received_bytes= progressBar.value;
  req2.resume();
        }
回答如下:

假设你想继续下载中断的地方,并且你将'total_bytes'和'received_bytes'存储为全局变量,那么你的进度条就会重新建立起来。你的简历22应该......

function resume22() {
      console.log('RESUME function called');
      progressBar.max=total_bytes;
      console.log(progressBar.max);
      progressBar.value = received_bytes;
      console.log(progressBar.value);
      req2.resume();
    }
发布评论

评论列表 (0)

  1. 暂无评论