def generate_hash(file_path: str | Path, algorithm: str = "sha256") -> str:
    """Generate a hash of a file using the specified algorithm.

    Args:
        file_path: Path to the file to hash
        algorithm: Hashing algorithm to use (e.g. 'sha256', 'sha3_512')

    Returns:
        Hexadecimal hash string of the file

    Raises:
        ValueError: If the specified hashing algorithm is not supported
    """
    # Get the hashing algorithm.
    try:
        hasher = getattr(hashlib, algorithm)()
    except AttributeError as err:
        msg = f"Unsupported hashing algorithm: {algorithm}"
        raise ValueError(msg) from err

    # Read the file in chunks to avoid loading it all into memory
    with Path(file_path).open("rb") as file:
        for chunk in iter(lambda: file.read(4096), b""):
            hasher.update(chunk)

    # Return the computed hash value in hexadecimal format
    return hasher.hexdigest()
Generate a hash of a file using the specified algorithm.

    Args:
        file_path: Path to the file to hash
        algorithm: Hashing algorithm to use (e.g. 'sha256', 'sha3_512')

    Returns:
        Hexadecimal hash string of the file

    Raises:
        ValueError: If the specified hashing algorithm is not supported
    
src/anomalib/data/utils/download.py