summaryrefslogtreecommitdiff
path: root/lib/comp/compressor.c
blob: 1ede111d17c59ad17a21777558da85e1de01a31a (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
/* SPDX-License-Identifier: GPL-3.0-or-later */
#include <string.h>

#include "internal.h"

typedef compressor_t *(*compressor_fun_t)(bool compress, size_t block_size);

static compressor_fun_t compressors[SQFS_COMP_MAX + 1] = {
#ifdef WITH_GZIP
	[SQFS_COMP_GZIP] = create_gzip_compressor,
#endif
#ifdef WITH_XZ
	[SQFS_COMP_XZ] = create_xz_compressor,
#endif
};

bool compressor_exists(E_SQFS_COMPRESSOR id)
{
	if (id < SQFS_COMP_MIN || id > SQFS_COMP_MAX)
		return false;

	return (compressors[id] != NULL);
}

compressor_t *compressor_create(E_SQFS_COMPRESSOR id, bool compress,
				size_t block_size)
{
	if (id < SQFS_COMP_MIN || id > SQFS_COMP_MAX)
		return NULL;

	if (compressors[id] == NULL)
		return NULL;

	return compressors[id](compress, block_size);
}