import hashlib


def checksum(filepath, hash_type='md5'):
    """

    Args:
        filepath:
        hash_type: str, support 'md5', 'sha1', 'sha224', 'sha256', 'sha384', 'sha512'

    Returns:
        str
    """
    _size = 4096

    m = getattr(hashlib, hash_type)()
    with open(filepath, 'rb') as fp:
        # data = fp.read(_size)
        # while data:
        #     m.update(data)
        #     data = fp.read(_size)
        for chunk in iter(lambda: fp.read(_size), b''):
            m.update(chunk)
    return m.hexdigest()