Skip to content

Instantly share code, notes, and snippets.

@Constaline
Forked from sakiyukiko/node-md5.js
Created August 4, 2018 14:10
Show Gist options
  • Save Constaline/9c48ef4b4ad1a0322b20579fd8d715a3 to your computer and use it in GitHub Desktop.
Save Constaline/9c48ef4b4ad1a0322b20579fd8d715a3 to your computer and use it in GitHub Desktop.
node.js大文件MD5值计算
var fs = require('fs');
var crypto = require('crypto');
var path = '/target/file.data';
var start = new Date().getTime();
var md5sum = crypto.createHash('md5');
var 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