Skip to content
Snippets Groups Projects
fsutils.py 567 B
Newer Older
import io, hashlib
#
# 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