Last active
August 29, 2015 13:56
-
-
Save mzyy94/9209459 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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