Created
June 8, 2017 20:29
-
-
Save JimDennis/209f6281b5be452b01cb4ee3f89686cc 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
#!/usr/local/bin/python3 | |
from __future__ import print_function | |
import hashlib, sys | |
def compute_checksum(filehandle): | |
results = hashlib.md5() | |
while True: | |
data = filehandle.read(1024*1024) # one mega at a time | |
if len(data) == 0: | |
break | |
results.update(data) | |
return results | |
if __name__ == '__main__': | |
args = sys.argv[1:] | |
if not args: | |
print('Must supply some filenames', file=sys.stderr) | |
sys.exit(1) | |
for each in args: | |
try: | |
with open(each, 'rb') as f: | |
md5 = compute_checksum(f) | |
except EnvironmentError as err: | |
print('Error handling %s: %s' % (each, err), file=sys.stderr) | |
continue | |
print(md5.hexdigest(), '\t', each) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment