async def METHOD_NAME(request: MaybeExtractArchiveRequest) -> ExtractedArchive:
    """If digest contains a single archive file, extract it, otherwise return the input digest."""
    extract_archive_dir = "__extract_archive_dir"
    snapshot, output_dir_digest = await MultiGet(
        Get(Snapshot, Digest, request.digest),
        Get(Digest, CreateDigest([Directory(extract_archive_dir)])),
    )
    if len(snapshot.files) != 1:
        return ExtractedArchive(request.digest)
    archive_path = snapshot.files[0]
    archive_suffix = request.use_suffix or "".join(PurePath(archive_path).suffixes)
    is_zip = archive_suffix.endswith(".zip")
    is_tar = archive_suffix.endswith(
        (".tar", ".tar.gz", ".tgz", ".tar.bz2", ".tbz2", ".tar.xz", ".txz", ".tar.lz4")
    )
    is_gz = not is_tar and archive_suffix.endswith(".gz")
    if not is_zip and not is_tar and not is_gz:
        return ExtractedArchive(request.digest)
    merge_digest_get = Get(Digest, MergeDigests((request.digest, output_dir_digest)))
    env = {}
    append_only_caches: FrozenDict[str, str] = FrozenDict({})
    if is_zip:
        input_digest, unzip_binary = await MultiGet(merge_digest_get, Get(UnzipBinary))
        argv = unzip_binary.extract_archive_argv(archive_path, extract_archive_dir)
    elif is_tar:
        input_digest, tar_binary = await MultiGet(merge_digest_get, Get(TarBinary))
        argv = tar_binary.extract_archive_argv(
            archive_path, extract_archive_dir, archive_suffix=archive_suffix
        )
        # `tar` expects to find a couple binaries like `gzip` and `xz` by looking on the PATH.
        env = {"PATH": os.pathsep.join(SEARCH_PATHS)}
    else:
        input_digest, gunzip = await MultiGet(merge_digest_get, Get(GunzipBinary))
        argv = gunzip.extract_archive_argv(archive_path, extract_archive_dir)
        append_only_caches = gunzip.python_binary.APPEND_ONLY_CACHES
    result = await Get(
        ProcessResult,
        Process(
            argv=argv,
            env=env,
            input_digest=input_digest,
            description=f"Extract {archive_path}",
            level=LogLevel.DEBUG,
            output_directories=(extract_archive_dir,),
            append_only_caches=append_only_caches,
        ),
    )
    resulting_digest = await Get(Digest, RemovePrefix(result.output_digest, extract_archive_dir))
    return ExtractedArchive(resulting_digest)