Last active
June 16, 2021 20:04
-
-
Save nicholatian/594cb51cfeb67f57209e3f8b42e82513 to your computer and use it in GitHub Desktop.
Streaming solution to sha256 checksum a file’s contents
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
#!/usr/bin/env python3 | |
def sha2_256sum(filename): | |
import hashlib | |
f = open(filename, 'rb') | |
data_hash = hashlib.sha256() | |
# Read and update hash string value in blocks of 4K | |
for block in iter(lambda: f.read(4096), b''): | |
data_hash.update(block) | |
digest = data_hash.hexdigest() | |
f.close() | |
return digest |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment