Created
July 17, 2020 05:29
-
-
Save odoku/0edf457159a028f31b2fc9290cb485fd to your computer and use it in GitHub Desktop.
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 | |
def compute_file_checksum( | |
filepath: str, | |
algorithm: str = "md5", | |
chunk_size: int = 1024, | |
) -> str: | |
hasher = hashlib.new(algorithm) | |
with open(filepath, "rb") as fp: | |
while True: | |
buffer = fp.read(chunk_size * hasher.block_size) | |
if not buffer: | |
break | |
hasher.update(buffer) | |
return hasher.hexdigest() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment