Skip to content

Instantly share code, notes, and snippets.

@JonnoFTW
Forked from aunyks/large-file-hash.py
Last active August 23, 2023 07:01
Show Gist options
  • Save JonnoFTW/275f6f3624ee5c3215e04becc0158ec2 to your computer and use it in GitHub Desktop.
Save JonnoFTW/275f6f3624ee5c3215e04becc0158ec2 to your computer and use it in GitHub Desktop.
Hash a large file in Python
import hashlib as hash
# Specify how many bytes of the file you want to open at a time
BLOCKSIZE = 1024 * 1024 * 8 # 8mb
def hash_file(fname: str):
sha = sha256()
with open(fname, 'rb') as fh:
while buff := fh.read(BLOCKSIZE):
sha.update(buff)
return sha.hexdigest()
print(hash_file('some_file.iso'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment