diff options
author | David Oberhollenzer <david.oberhollenzer@sigma-star.at> | 2019-08-12 18:25:52 +0200 |
---|---|---|
committer | David Oberhollenzer <david.oberhollenzer@sigma-star.at> | 2019-08-16 16:47:24 +0200 |
commit | 2f22a35e843a24f0ad5f31644133d64648fe4efc (patch) | |
tree | 7175b11355ea988c022d7e87b27f6676c5d2d181 /lib/comp/zstd.c | |
parent | 008990af4d8b0cfa03fcb2c5fa2ba461dad71b18 (diff) |
Add deep-copy function to compressor interface
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'lib/comp/zstd.c')
-rw-r--r-- | lib/comp/zstd.c | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/lib/comp/zstd.c b/lib/comp/zstd.c index 252e1bf..e206338 100644 --- a/lib/comp/zstd.c +++ b/lib/comp/zstd.c @@ -88,6 +88,29 @@ static ssize_t zstd_uncomp_block(compressor_t *base, const uint8_t *in, return ret; } +static compressor_t *zstd_create_copy(compressor_t *cmp) +{ + zstd_compressor_t *zstd = malloc(sizeof(*zstd)); + + if (zstd == NULL) { + perror("creating additional zstd compressor"); + return NULL; + } + + memcpy(zstd, cmp, sizeof(*zstd)); + + zstd->zctx = ZSTD_createCCtx(); + + if (zstd->zctx == NULL) { + fputs("error creating addtional zstd compression context\n", + stderr); + free(zstd); + return NULL; + } + + return (compressor_t *)zstd; +} + static void zstd_destroy(compressor_t *base) { zstd_compressor_t *zstd = (zstd_compressor_t *)base; @@ -141,6 +164,7 @@ compressor_t *create_zstd_compressor(bool compress, size_t block_size, base->do_block = compress ? zstd_comp_block : zstd_uncomp_block; base->write_options = zstd_write_options; base->read_options = zstd_read_options; + base->create_copy = zstd_create_copy; return base; fail_level: fprintf(stderr, "zstd compression level must be a number in the range " |