Skip to content

Commit

Permalink
Download progress bar using progress.
Browse files Browse the repository at this point in the history
  • Loading branch information
corwin-of-amber committed Jul 29, 2020
1 parent 57e8ff0 commit 3e5e4d4
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"download": "^5.0.3",
"file-exists": "^2.0.0",
"merge": "^1.2.0",
"multimeter": "^0.1.1",
"progress": "^2.0.3",
"rimraf": "^2.2.8",
"semver": "^5.1.0",
"yargs": "^3.2.1"
Expand Down
18 changes: 15 additions & 3 deletions scripts/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
var download = require('download');
var rimraf = require('rimraf');
var semver = require('semver');
var createBar = require('multimeter')(process);
var ProgressBar = require('progress')
var path = require('path');
var fs = require('fs');
var merge = require('merge');
Expand Down Expand Up @@ -79,7 +79,7 @@ if (!url) logError('Could not find a compatible version of nw.js to download for
var dest = path.resolve(__dirname, '..', 'nwjs');
rimraf.sync(dest);

var bar = createBar({ before: url + ' [' });
var bar = new ProgressBar(url + ' [:bar] :current/:totalM', 100);

var total = 0;
var progress = 0;
Expand All @@ -103,7 +103,19 @@ if( parsedUrl.protocol == 'file:' ) {
.use( Decompress.targz(decompressOptions) )
.run( cb );
} else {
download(url, dest, merge({ extract: true }, decompressOptions))
var progress = { total: null, downloaded: 0,
start: function(resp) {
this.total = parseInt(resp.headers['content-length']);
bar.total = (this.total / 1e6).toFixed(2);
},
recvd: function(chunk) {
this.downloaded += chunk.length;
if (this.total) { bar.update(this.downloaded / this.total); }
}
};
download(url, dest, merge({ extract: true }, decompressOptions))
.on('response', function(resp) { progress.start(resp); })
.on('data', function(chunk) { progress.recvd(chunk); })
.then(function() {cb();})
.catch(function(e) {cb(e);});
}

0 comments on commit 3e5e4d4

Please sign in to comment.