Created
June 11, 2013 23:49
-
-
Save aleroddepaz/5761824 to your computer and use it in GitHub Desktop.
Script to verify data integrity using the MD5 hash.
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 sys | |
import hashlib | |
from functools import partial | |
def md5sum(filename): | |
with open(filename, mode="rb") as f: | |
md5 = hashlib.md5() | |
buf_size = md5.block_size * 64 | |
for buf in iter(partial(f.read, buf_size), b''): | |
md5.update(buf) | |
return md5.hexdigest() | |
if __name__ == "__main__": | |
if len(sys.argv) < 2: | |
print("USAGE: {} <file>".format(sys.argv[0])) | |
sys.exit(1) | |
try: | |
print(md5sum(sys.argv[1])) | |
except Exception as e: | |
print(e) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment