Created
May 7, 2024 13:07
-
-
Save kosinix/758fdb3c5d0257bf1025afaa331bbba0 to your computer and use it in GitHub Desktop.
Generate hash of text file contents Nodejs for checksum
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 { readFileSync } = require('fs') | |
const getHash = (fileBuffer) => { | |
const hashSum = crypto.createHash('sha256') | |
hashSum.update(fileBuffer) | |
const hex = hashSum.digest('hex') | |
return hex | |
} | |
let file = readFileSync(`file.txt`) | |
getHash(file) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment