Skip to content

Instantly share code, notes, and snippets.

@simonthompson99
Last active January 15, 2021 12:11
Show Gist options
  • Select an option

  • Save simonthompson99/044b5c451325ae74fd1dfc53d6093842 to your computer and use it in GitHub Desktop.

Select an option

Save simonthompson99/044b5c451325ae74fd1dfc53d6093842 to your computer and use it in GitHub Desktop.
[Generate md5sum of file] Generate MD5 sum for a given file path #python
import hashlib
def md5(fname):
"""
returns the md5 for a filepath
"""
BLOCKSIZE = 65536
hasher = hashlib.md5()
with open(fname, 'rb') as afile:
buf = afile.read(BLOCKSIZE)
while len(buf) > 0:
hasher.update(buf)
buf = afile.read(BLOCKSIZE)
return hasher.hexdigest()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment