Skip to content

Commit

Permalink
[bin] Add a download progress bar
Browse files Browse the repository at this point in the history
  • Loading branch information
mmalecki committed Feb 14, 2013
1 parent 5688fe4 commit b1117d2
Showing 1 changed file with 20 additions and 5 deletions.
25 changes: 20 additions & 5 deletions lib/jitsu/commands/snapshots.js
Expand Up @@ -5,11 +5,12 @@
*
*/

var fs = require('fs'),
semver = require('semver'),
dateformat = require('dateformat'),
jitsu = require('../../jitsu'),
utile = jitsu.common;
var fs = require('fs'),
semver = require('semver'),
dateformat = require('dateformat'),
jitsu = require('../../jitsu'),
ProgressBar = require('progress'),
utile = jitsu.common;

var snapshots = exports;

Expand Down Expand Up @@ -278,9 +279,23 @@ snapshots.fetch = function (name, callback) {
return callback(new Error('Unknown status code: ' + res.statusCode));
}

var bar = new ProgressBar('info'.green + '\t Downloading: [:bar] :percent',{
total: parseInt(res.headers['content-length'], 10),
width: 30,
complete: '=',
incomplete: ' '
});

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

res.on('end', console.log);

var filename = appName.replace('/', '-') + '-' + snapshot.id + '.tgz';
res.pipe(fs.createWriteStream(filename)).on('close', function () {
jitsu.log.info('Snapshot ' + snapshot.id + ' saved to file ' + filename + '.');
return callback();
});
});
}
Expand Down

0 comments on commit b1117d2

Please sign in to comment.