import hashlib
from pathlib import Path


def md5(fname):
    """
    Calculates the md5sum of the passed file and returns the calculated value.

    Parameters
    ----------
    fname: str
        filename of file to calculate the md5sum for

    Returns
    --------
    str
        md5sum of passed file
    """
    hash_md5 = hashlib.md5()
    if isinstance(fname, str):
        fname = Path(fname)
    assert isinstance(fname, Path)
    assert fname.exists()
    with open(str(fname), "rb") as file_of_interest:
        for chunk in iter(lambda: file_of_interest.read(4096), b""):
            hash_md5.update(chunk)
    return hash_md5.hexdigest()