]> wimlib.net Git - wimlib/blob - src/zstd_decompress.c
[EXPERIMENTAL, FOR BENCHMARKING ONLY] Zstandard compression support
[wimlib] / src / zstd_decompress.c
1 #ifdef HAVE_CONFIG_H
2 #  include "config.h"
3 #endif
4
5 #include "wimlib/error.h"
6 #include "wimlib/decompressor_ops.h"
7 #include "wimlib/util.h"
8
9 #include <zstd.h>
10
11 static int
12 zstd_create_decompressor(size_t max_block_size, void **d_ret)
13 {
14         *d_ret = ZSTD_createDCtx();
15         if (!*d_ret)
16                 return WIMLIB_ERR_NOMEM;
17         return 0;
18 }
19
20 static int
21 zstd_decompress(const void *in, size_t in_nbytes,
22                 void *out, size_t out_nbytes, void *_d)
23 {
24         size_t res = ZSTD_decompressDCtx(_d, out, out_nbytes, in, in_nbytes);
25         if (res != out_nbytes)
26                 return -1;
27         return 0;
28 }
29
30 static void
31 zstd_free_decompressor(void *_d)
32 {
33         ZSTD_freeDCtx(_d);
34 }
35
36 const struct decompressor_ops zstd_decompressor_ops = {
37         .create_decompressor    = zstd_create_decompressor,
38         .decompress             = zstd_decompress,
39         .free_decompressor      = zstd_free_decompressor,
40 };