-
-
Save JonnoFTW/275f6f3624ee5c3215e04becc0158ec2 to your computer and use it in GitHub Desktop.
Hash a large file in Python
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
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