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/gzip.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/gzip.c')
-rw-r--r-- | lib/comp/gzip.c | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/lib/comp/gzip.c b/lib/comp/gzip.c index 1068520..1fdc051 100644 --- a/lib/comp/gzip.c +++ b/lib/comp/gzip.c @@ -308,6 +308,36 @@ fail_value: return -1; } +static compressor_t *gzip_create_copy(compressor_t *cmp) +{ + gzip_compressor_t *gzip = malloc(sizeof(*gzip)); + int ret; + + if (gzip == NULL) { + perror("creating additional gzip compressor"); + return NULL; + } + + memcpy(gzip, cmp, sizeof(*gzip)); + memset(&gzip->strm, 0, sizeof(gzip->strm)); + + if (gzip->compress) { + ret = deflateInit2(&gzip->strm, gzip->opt.level, Z_DEFLATED, + gzip->opt.window, 8, Z_DEFAULT_STRATEGY); + } else { + ret = inflateInit(&gzip->strm); + } + + if (ret != Z_OK) { + fputs("internal error creating additional zlib stream\n", + stderr); + free(gzip); + return NULL; + } + + return (compressor_t *)gzip; +} + compressor_t *create_gzip_compressor(bool compress, size_t block_size, char *options) { @@ -340,6 +370,7 @@ compressor_t *create_gzip_compressor(bool compress, size_t block_size, base->destroy = gzip_destroy; base->write_options = gzip_write_options; base->read_options = gzip_read_options; + base->create_copy = gzip_create_copy; if (compress) { ret = deflateInit2(&gzip->strm, level, Z_DEFLATED, window, 8, |