Created
August 1, 2017 04:09
-
-
Save F1LT3R/2e4347a6609c3d0105afce68cd101561 to your computer and use it in GitHub Desktop.
sha1 hash node.js
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
const crypto = require('crypto') | |
const sha1 = path => new Promise((resolve, reject) => { | |
const hash = crypto.createHash('sha1') | |
const rs = fs.createReadStream(path) | |
rs.on('error', reject) | |
rs.on('data', chunk => hash.update(chunk)) | |
rs.on('end', () => resolve(hash.digest('hex'))) | |
}) | |
sha1('./test.txt').then(hash => { | |
console.log(hash) | |
}).catch(err => { | |
throw new Error(err) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
thanks bro