Skip to content

Instantly share code, notes, and snippets.

@JimDennis
Created Jun 8, 2017
Embed
What would you like to do?
#!/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