Skip to content
Snippets Groups Projects
fsutils.py 575 B
Newer Older
Jean-Philippe Laverdure's avatar
Jean-Philippe Laverdure committed
import hashlib
import io

#
# def md5sum(src, callback, length=io.DEFAULT_BUFFER_SIZE):
#     calculated = 0
#     md5 = hashlib.md5()
#     with io.open(src, mode="rb") as fd:
#         for chunk in iter(lambda: fd.read(length), b''):
#             md5.update(chunk)
#             calculated += len(chunk)
#             callback(calculated)
#     return md5

def md5sum(src, length=io.DEFAULT_BUFFER_SIZE):
    md5 = hashlib.md5()
    with io.open(src, mode="rb") as fd:
        for chunk in iter(lambda: fd.read(length), b''):
            md5.update(chunk)
    return md5