def compute_hash(file_path, hash_function, digest_size=None):
    """Compute the hash of a file using the specified hash function."""
    try:
        with open(file_path, 'rb') as file:
            if digest_size:
                return hash_function(file.read(), digest_size=digest_size).hexdigest()
            return hash_function(file.read()).hexdigest()
    except IOError as e:
        print(f"Error reading file {file_path}: {e}")
        return None
Compute the hash of a file using the specified hash function.
winpython/hash.py