diff options
author | David Oberhollenzer <david.oberhollenzer@sigma-star.at> | 2019-04-30 10:50:13 +0200 |
---|---|---|
committer | David Oberhollenzer <david.oberhollenzer@sigma-star.at> | 2019-05-02 12:40:06 +0200 |
commit | a85c6025903a2b6e97e1938b201b3361a0cbed66 (patch) | |
tree | cf92df4ba782c4b9c4a49dcf1cc3e25f849723a9 /lib/comp/compressor.c | |
parent | fa7f378bf627ddcfd7a93a000149e4d8c3810bf5 (diff) |
Add compressor library
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'lib/comp/compressor.c')
-rw-r--r-- | lib/comp/compressor.c | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/lib/comp/compressor.c b/lib/comp/compressor.c new file mode 100644 index 0000000..3bc2b4d --- /dev/null +++ b/lib/comp/compressor.c @@ -0,0 +1,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_ZLIB + [SQFS_COMP_GZIP] = create_zlib_compressor, +#endif +#ifdef WITH_LZMA + [SQFS_COMP_XZ] = create_lzma_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); +} |