Created
January 6, 2016 17:58
-
-
Save thattommyhall/c8a8a912ad6765277743 to your computer and use it in GitHub Desktop.
checksum generation
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
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