Created
January 24, 2021 04:45
-
-
Save billywhizz/bcb351567e6f116ee2d7c12e2f68ce0c to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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