summaryrefslogtreecommitdiff
path: root/lib/fstream/compressor.c
blob: 84a859cd3a9b235c5d97e7a96b52a18975a6a0e5 (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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/* SPDX-License-Identifier: GPL-3.0-or-later */
/*
 * compressor.c
 *
 * Copyright (C) 2019 David Oberhollenzer <goliath@infraroot.at>
 */
#include "internal.h"

int fstream_compressor_id_from_name(const char *name)
{
	if (strcmp(name, "gzip") == 0)
		return FSTREAM_COMPRESSOR_GZIP;

	if (strcmp(name, "xz") == 0)
		return FSTREAM_COMPRESSOR_XZ;

	if (strcmp(name, "zstd") == 0)
		return FSTREAM_COMPRESSOR_ZSTD;

	return -1;
}

const char *fstream_compressor_name_from_id(int id)
{
	if (id == FSTREAM_COMPRESSOR_GZIP)
		return "gzip";

	if (id == FSTREAM_COMPRESSOR_XZ)
		return "xz";

	if (id == FSTREAM_COMPRESSOR_ZSTD)
		return "zstd";

	return NULL;
}

bool fstream_compressor_exists(int id)
{
	switch (id) {
#ifdef WITH_GZIP
	case FSTREAM_COMPRESSOR_GZIP:
		return true;
#endif
#ifdef WITH_XZ
	case FSTREAM_COMPRESSOR_XZ:
		return true;
#endif
#ifdef WITH_ZSTD
	case FSTREAM_COMPRESSOR_ZSTD:
		return true;
#endif
	default:
		break;
	}

	return false;
}