from typing import Optional
import hashlib


def check_md5(filepath: str, md5_value: Optional[str] = None) -> bool:
    """
    check MD5 signature of specified file.

    Args:
        filepath: path of source file to verify MD5.
        md5_value: expected MD5 value of the file.

    """
    if md5_value is not None:
        md5 = hashlib.md5()
        with open(filepath, "rb") as f:
            for chunk in iter(lambda: f.read(1024 * 1024), b""):
                md5.update(chunk)
        if md5_value != md5.hexdigest():
            return False
    else:
        print(f"expected MD5 is None, skip MD5 check for file {filepath}.")

    return True