def compress_tar(source_file, output_tarball, compress_mode='gz'):
    """
    Args:
        source_file: source file or folder
        output_tarball: output tar file name
        compress_mode: "gz", "bz2", "xz" or "" (empty for uncompressed write)
    """
    source_file, output_tarball = f_expand(source_file), f_expand(output_tarball)
    assert compress_mode in ['gz', 'bz2', 'xz', '']
    with tarfile.open(output_tarball, 'w:'+compress_mode) as tar:
        tar.add(source_file, arcname=os.path.basename(source_file))

    Args:
        source_file: source file or folder
        output_tarball: output tar file name
        compress_mode: "gz", "bz2", "xz" or "" (empty for uncompressed write)
    
surreal/utils/filesys.py