Last active
February 8, 2017 13:15
-
-
Save deehzee/af06125de8565dd6305e425ce56fdbd5 to your computer and use it in GitHub Desktop.
Compute MD5SUM of a 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
# Compute md5sum of a file | |
# File: md5sum.py | |
# Debajyoti Nandi | |
# 2016-11-09 | |
# Python 2 | |
import os | |
import hashlib | |
def md5sum(fname): | |
"""Find the md5sum hash of the content of a given file.""" | |
blocksize = 65536 | |
hash_md5 = hashlib.md5() | |
with open(fname, "rb") as f: | |
for block in iter(lambda: f.read(blocksize), b""): | |
hash_md5.update(block) | |
return hash_md5.hexdigest() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment