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) | |
}) |
@benjaminhoffman is right. 👍
async function hashOfStream(readable) {
return await once(
readable.pipe(crypto.createHash('sha1').setEncoding('hex')),
'finish')
}
thanks bro
Thank you!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
dont forget
const fs = require('fs')
.... it may be implied, but still.