summaryrefslogtreecommitdiff
path: root/lib/common/compress.c
blob: 3ee242d1f6cc155914cac8ab68be078498969a88 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/* SPDX-License-Identifier: GPL-3.0-or-later */
/*
 * compress.c
 *
 * Copyright (C) 2019 David Oberhollenzer <goliath@infraroot.at>
 */
#include "common.h"

SQFS_COMPRESSOR compressor_get_default(void)
{
	if (sqfs_compressor_exists(SQFS_COMP_XZ))
		return SQFS_COMP_XZ;

	if (sqfs_compressor_exists(SQFS_COMP_ZSTD))
		return SQFS_COMP_ZSTD;

	return SQFS_COMP_GZIP;
}

void compressor_print_available(void)
{
	bool have_compressor;
	int i;

	fputs("Available compressors:\n", stdout);

	for (i = SQFS_COMP_MIN; i <= SQFS_COMP_MAX; ++i) {
		have_compressor = sqfs_compressor_exists(i);

#ifdef WITH_LZO
		if (i == SQFS_COMP_LZO)
			have_compressor = true;
#endif

		if (have_compressor)
			printf("\t%s\n", sqfs_compressor_name_from_id(i));
	}

	printf("\nDefault compressor: %s\n",
	       sqfs_compressor_name_from_id(compressor_get_default()));
}