- 
      
- 
        Save Constaline/9c48ef4b4ad1a0322b20579fd8d715a3 to your computer and use it in GitHub Desktop. 
    node.js大文件MD5值计算
  
        
  
    
      This file contains hidden or 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
    
  
  
    
  | 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