Skip to content

Instantly share code, notes, and snippets.

@lushijie
Created February 9, 2018 03: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 lushijie/050eec05ed13bf9ba769b6467f4d201a to your computer and use it in GitHub Desktop.
Save lushijie/050eec05ed13bf9ba769b6467f4d201a to your computer and use it in GitHub Desktop.
计算文件md5
let fs = require('fs');
let crypto = require('crypto');
let path = '/Users/lushijie/Pictures/day1.jpg';
let start = new Date().getTime();
let md5sum = crypto.createHash('md5');
let stream = fs.createReadStream(path);
stream.on('data', function(chunk) {
md5sum.update(chunk);
});
stream.on('end', function() {
str = md5sum.digest('hex').toUpperCase();
console.log('文件:'+path+',MD5签名为:'+str+'.耗时:'+(new Date().getTime()-start)/1000.00+"秒");
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment