Skip to content

Instantly share code, notes, and snippets.

@seanpue
Created May 20, 2020 00:29
Show Gist options
  • Save seanpue/a66ab3d67e3d21c7d845a0093ccdc055 to your computer and use it in GitHub Desktop.
Save seanpue/a66ab3d67e3d21c7d845a0093ccdc055 to your computer and use it in GitHub Desktop.
Generate md5checksum of local file equivalent to Google Drive/Cloud Storage's
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