Created
June 21, 2024 14:12
-
-
Save jeftarmascarenhas/f201588f37ec506306b84121e74e62ea to your computer and use it in GitHub Desktop.
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 fs = require("fs"); | |
const crypto = require("crypto"); | |
function createHash(file) { | |
return new Promise((resolve, reject) => { | |
const hash = crypto.createHash("sha256"); | |
const stream = fs.createReadStream(file); | |
stream.on("data", (chunk) => { | |
hash.update(chunk); | |
}); | |
stream.on("end", () => { | |
const hashHex = hash.digest("hex"); | |
console.log(`Hash Created: ${hashHex}`); | |
return resolve(hashHex); | |
}); | |
stream.on("error", (err) => reject(err)); | |
}); | |
} | |
createHash("./MyDoc.md").catch(console.log); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment