Last active
January 14, 2016 19:06
-
-
Save gustavofonseca/feb12ef62fd7f1643b5b to your computer and use it in GitHub Desktop.
This file contains 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
import hashlib | |
def checksum_file(filepath, algorithm=hashlib.md5): | |
""" | |
Calcula o ``checksum`` de um arquivo em disco. | |
:param filepath: caminho no sistema de arquivos. | |
:param algorithm: (opcional) o padrão é ``hashlib.md5``. | |
""" | |
with open(filepath, 'rb') as fp: | |
hash = algorithm() | |
while True: | |
chunk = fp.read(1024) | |
if not chunk: | |
break | |
hash.update(chunk) | |
return hash.hexdigest() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment