Created
May 20, 2020 00:29
-
-
Save seanpue/a66ab3d67e3d21c7d845a0093ccdc055 to your computer and use it in GitHub Desktop.
Generate md5checksum of local file equivalent to Google Drive/Cloud Storage's
This file contains hidden or 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
from hashlib import md5 | |
def google_md5sum(filen): | |
"""Return Google Drive /Cloud Storage hexadecimal equivalent md5sum. | |
Updates md5 hashalg by reading 8k chunks. Adapted from gsutil.""" | |
hashalg = md5() | |
with open(filen, "rb") as f: | |
f.seek(0) | |
while True: | |
data = f.read(8 * 1024) | |
if not data: | |
break | |
hashalg.update(data) | |
return hashalg.hexdigest() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment