Skip to content

Instantly share code, notes, and snippets.

@albertzaharovits
Created March 23, 2015 13:34
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save albertzaharovits/4f692286a9ae288e4a58 to your computer and use it in GitHub Desktop.
Save albertzaharovits/4f692286a9ae288e4a58 to your computer and use it in GitHub Desktop.
def get_hash(file_path, hash_name="sha256", block_size=4096):
# hash_name = md5 / sha256 / sha512
hash = hashlib.new(hash_name)
with open(file_path, "rb") as f:
for block in iter(lambda: f.read(block_size), ""):
hash.update(block)
return hash.hexdigest()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment