Skip to content

Instantly share code, notes, and snippets.

@mwalzer
Created March 6, 2020 09:33
Show Gist options
  • Save mwalzer/efcb74e722c22a60abf6e98083af4dbe to your computer and use it in GitHub Desktop.
Save mwalzer/efcb74e722c22a60abf6e98083af4dbe to your computer and use it in GitHub Desktop.
import hashlib
def sha256fromfile(filename: str) -> str:
sha = hashlib.sha256()
b = bytearray(128*1024)
mv = memoryview(b)
with open(filename, 'rb', buffering=0) as f:
for n in iter(lambda : f.readinto(mv), 0):
sha.update(mv[:n])
return sha.hexdigest()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment