Created
February 9, 2018 03:56
-
-
Save lushijie/050eec05ed13bf9ba769b6467f4d201a to your computer and use it in GitHub Desktop.
计算文件md5
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
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