简体   繁体   中英

Node progress bar

I am currently working on the example presented in the https://github.com/tj/node-progress

I have followed the example word to word, but can't seem to get the functionality of bar.tick() working

var req = http.request({
    host: 'download.github.com',
    port: 443,
    path: '/visionmedia-node-jscoverage-0d4608a.zip'
});

req.on('response', function (res) {
    //var body = "";
    var len = parseInt(res.headers['content-length'], 10);
    console.log();
    var bar = new ProgressBar(' downloading :bar :percent :etas', {
        complete: '=',
        incomplete: ' ',
        width: 20,
        total: len
    });

    res.on('data', function (chunk) {
        //body += chunk;
        bar.tick(chunk.length);
    });

    res.on('end', function () {
        console.log('\nFinished Loading\n');
    });

});

req.end();

The final output looks like the following

downloading ==================== 100% 0.0s

But instead should show the progress as the data is received until complete

确保您实际上正在下载某些东西,该文件可能已被删除或其他任何东西,因此您的下载即将完成,因为没有要下载的内容。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM