import hashlib


def _hash_file(fpath, chunk_size=65535):
    """
    Calculates the md5 hash of a file

    :param fpath: path to the file being validated
    :param chunk_size: Bytes to read at a time (leave unless large files)
    :return: The file hash
    """
    hasher = hashlib.md5()

    with open(fpath, 'rb') as fpath_file:
        for chunk in iter(lambda: fpath_file.read(chunk_size), b''):
            hasher.update(chunk)

    return hasher.hexdigest()