Skip to content

Instantly share code, notes, and snippets.

@mzyy94
Last active August 29, 2015 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mzyy94/9209459 to your computer and use it in GitHub Desktop.
Save mzyy94/9209459 to your computer and use it in GitHub Desktop.
if (process.argv.length != 3) {
console.error('usage:',
process.argv[0],
process.argv[1],
'<archive url>');
process.exit(1);
}
var url = process.argv[2];
var http = require(url.split(':')[0]);
var crypto = require('crypto');
var fs = require('fs');
var zlib = require('zlib');
var path = require('path');
http.get(url, function(res) {
var filename = path.basename(url, '.gz');
var output = fs.createWriteStream(filename);
var md5 = crypto.createHash('md5');
var gunzip = zlib.createGunzip();
console.log('downloading archive data.', filename);
res.pipe(gunzip).pipe(output);
gunzip.on('data', function(data) {
md5.update(data);
});
gunzip.on('end', function() {
output.close();
console.log('done.');
var md5sum = md5.digest('hex');
console.log('md5=', md5sum);
});
}).on('error', function(err) {
console.log('error', err);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment