Skip to content

Instantly share code, notes, and snippets.

@tgardiner
Last active January 13, 2019 02:54
Show Gist options
  • Save tgardiner/be18d1cc965d0f8ebb1e99b87595aee5 to your computer and use it in GitHub Desktop.
Save tgardiner/be18d1cc965d0f8ebb1e99b87595aee5 to your computer and use it in GitHub Desktop.
Calculate AWS S3 Etag for local file
def calc_etag(inputfile, partsize):
md5_digests = []
with open(inputfile, 'rb') as f:
for chunk in iter(lambda: f.read(partsize), b''):
md5_digests.append(md5(chunk).digest())
return md5(b''.join(md5_digests)).hexdigest() + '-' + str(len(md5_digests))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment