from pathlib import Path
import hashlib


def file_md5sum(filepath: Path) -> str:
    """
    Generates a md5sum for a file. Reads file in blocks to save memory.
    :param filepath: a pathlib. Path to the file
    :return: a md5sum as hexadecimal string.
    """
    hasher = hashlib.md5()
    with filepath.open('rb') as file_handler:  # Read the file in bytes
        for block in iter(lambda: file_handler.read(8192), b''):
            hasher.update(block)
    return hasher.hexdigest()