Skip to content

Instantly share code, notes, and snippets.

@billywhizz
Created January 24, 2021 04:45
Show Gist options
  • Save billywhizz/bcb351567e6f116ee2d7c12e2f68ce0c to your computer and use it in GitHub Desktop.
Save billywhizz/bcb351567e6f116ee2d7c12e2f68ce0c to your computer and use it in GitHub Desktop.
function checksum (file) {
const source = Buffer.alloc(65536)
const fd = openSync(file)
const hash = createHash('sha256')
let bytes = readSync(fd, source)
while (bytes > 0) {
if (bytes < 65536) {
hash.update(source.slice(0, bytes))
} else {
hash.update(source)
}
bytes = readSync(fd, source)
}
return hash.digest('hex')
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment