Skip to content

Instantly share code, notes, and snippets.

@JimDennis
Created June 8, 2017 20:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JimDennis/209f6281b5be452b01cb4ee3f89686cc to your computer and use it in GitHub Desktop.
Save JimDennis/209f6281b5be452b01cb4ee3f89686cc to your computer and use it in GitHub Desktop.
#!/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