def extract(file_name: Path, root: Path) -> None:
    """Extract a compressed dataset file.

    Supports .zip, .tar, .gz, .xz and .tgz formats.

    Args:
        file_name: Path of the file to extract
        root: Root directory for extraction

    Raises:
        ValueError: If the file format is not recognized
    """
    logger.info(f"Extracting dataset into {root} folder.")

    # Safely extract zip files
    if file_name.suffix == ".zip":
        with ZipFile(file_name, "r") as zip_file:
            for file_info in zip_file.infolist():
                if not is_file_potentially_dangerous(file_info.filename):
                    zip_file.extract(file_info, root)

    # Safely extract tar files.
    elif file_name.suffix in {".tar", ".gz", ".xz", ".tgz"}:
        with tarfile.open(file_name) as tar_file:
            members = tar_file.getmembers()
            safe_members = [member for member in members if not is_file_potentially_dangerous(member.name)]
            safe_extract(tar_file, root, safe_members)

    else:
        msg = f"Unrecognized file format: {file_name}"
        raise ValueError(msg)

    logger.info("Cleaning up files.")
    file_name.unlink()
Extract a compressed dataset file.

    Supports .zip, .tar, .gz, .xz and .tgz formats.

    Args:
        file_name: Path of the file to extract
        root: Root directory for extraction

    Raises:
        ValueError: If the file format is not recognized
    
src/anomalib/data/utils/download.py