Skip to content

Instantly share code, notes, and snippets.

@thattommyhall
Created January 6, 2016 17:58
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 thattommyhall/c8a8a912ad6765277743 to your computer and use it in GitHub Desktop.
Save thattommyhall/c8a8a912ad6765277743 to your computer and use it in GitHub Desktop.
checksum generation
import hashlib
def md5sum(source_path, chunk_size=8388608):
md5s = []
with open(source_path,'rb') as fp:
while True:
data = fp.read(chunk_size)
if not data:
break
md5s.append(hashlib.md5(data))
if len(md5s) == 1:
return '"%s"' % (md5s[0].hexdigest())
digests = b"".join(m.digest() for m in md5s)
new_md5 = hashlib.md5(digests)
new_etag = '"%s-%s"' % (new_md5.hexdigest(),len(md5s))
return new_etag
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment