from pathlib import Path
import hashlib


def get_md5sum(src_file: Path, mode='b'):
    """Returns md5sum of file

    Parameters
    ----------
    src_file : str
        Filename to get md5sum for.
    mode : 't' or 'b'
        File mode to open file with. When in text mode, universal line endings
        are used to ensure consitency in hashes between platforms.
    """
    errors = 'surrogateescape' if mode == 't' else None
    with open(str(src_file), 'r' + mode, errors=errors) as src_data:
        src_content = src_data.read()
        if mode == 't':
            src_content = src_content.encode(errors=errors)
        return hashlib.md5(src_content).hexdigest()