Skip to content

Instantly share code, notes, and snippets.

@F1LT3R
Created August 1, 2017 04:09
Show Gist options
  • Save F1LT3R/2e4347a6609c3d0105afce68cd101561 to your computer and use it in GitHub Desktop.
Save F1LT3R/2e4347a6609c3d0105afce68cd101561 to your computer and use it in GitHub Desktop.
sha1 hash node.js
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)
})
@hungdev
Copy link

hungdev commented Sep 5, 2019

thanks bro

@colesiegel
Copy link

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment