import tarfile


def what_comp(filename):
    """
    Return what compression type based on file suffix passed.

    Currently based on suffix could be updated to be based on FileMagic
    Currently assumes input is a pathlib

    Current known versions:
    GZIP  .gz or .tgz
    BZ2   .bz2
    XZ    .xz or .lzma
    LZ4   .lz4
    None  None
    """

    # Grab current suffix, force lower case
    suffix = filename.suffix
    suffix = suffix.lower()

    # GZIP
    if suffix in [".gz", ".tgz"]:
        return "GZIP"
    elif suffix in [".bz2"]:
        return "BZ2"
    elif suffix in [".xz", ".lzma"]:
        return "XZ"
    elif suffix in [".lz4"]:
        return "LZ4"
    elif suffix in [".zst"]:
        return "ZSTD"

    # check that it's an actual tar file
    elif tarfile.is_tarfile(filename):
        # is a tar just without compression so continue
        return None
    else:
        # we don't know what this file is throw
        raise Exception(f"{filename} has unknown compression or not tar file")