diff options
author | David Oberhollenzer <david.oberhollenzer@sigma-star.at> | 2019-05-04 20:47:39 +0200 |
---|---|---|
committer | David Oberhollenzer <david.oberhollenzer@sigma-star.at> | 2019-05-04 22:22:48 +0200 |
commit | 7070857b47373dafc1ab93fadec79243da589a1a (patch) | |
tree | 760817fb41a74984a499bc88d5ae84d4a0a4ebb8 /lib/comp/zlib.c | |
parent | 2b975a449c17268f943403176a7609079b7af084 (diff) |
Rename lzma compressor to xz, zlib compressor to gzip
Stick to the terminology that SquashFS uses. SquashFS uses "lzma" to
refere to lzma1, "xz" to refere to lzma2 and confusingly "gzip" to
refere to raw zlib deflate. We can avoid a lot of confusion by
_consistently_ using the same terminology.
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'lib/comp/zlib.c')
-rw-r--r-- | lib/comp/zlib.c | 107 |
1 files changed, 0 insertions, 107 deletions
diff --git a/lib/comp/zlib.c b/lib/comp/zlib.c deleted file mode 100644 index f151132..0000000 --- a/lib/comp/zlib.c +++ /dev/null @@ -1,107 +0,0 @@ -/* SPDX-License-Identifier: GPL-3.0-or-later */ -#include <stdbool.h> -#include <stdlib.h> -#include <string.h> -#include <stdio.h> -#include <zlib.h> - -#include "internal.h" - -typedef struct { - compressor_t base; - - z_stream strm; - bool compress; - - size_t block_size; -} zlib_compressor_t; - -static void zlib_destroy(compressor_t *base) -{ - zlib_compressor_t *zlib = (zlib_compressor_t *)base; - - if (zlib->compress) { - deflateEnd(&zlib->strm); - } else { - inflateEnd(&zlib->strm); - } - - free(zlib); -} - -static ssize_t zlib_do_block(compressor_t *base, const uint8_t *in, - size_t size, uint8_t *out, size_t outsize) -{ - zlib_compressor_t *zlib = (zlib_compressor_t *)base; - size_t written; - int ret; - - if (zlib->compress) { - ret = deflateReset(&zlib->strm); - } else { - ret = inflateReset(&zlib->strm); - } - - if (ret != Z_OK) { - fputs("resetting zlib stream failed\n", stderr); - return -1; - } - - zlib->strm.next_in = (void *)in; - zlib->strm.avail_in = size; - zlib->strm.next_out = out; - zlib->strm.avail_out = outsize; - - if (zlib->compress) { - ret = deflate(&zlib->strm, Z_FINISH); - } else { - ret = inflate(&zlib->strm, Z_FINISH); - } - - if (ret == Z_STREAM_END) { - written = zlib->strm.total_out; - - if (zlib->compress && written >= size) - return 0; - - return (ssize_t)written; - } - - if (ret != Z_OK) { - fputs("zlib block processing failed\n", stderr); - return -1; - } - - return 0; -} - -compressor_t *create_zlib_compressor(bool compress, size_t block_size) -{ - zlib_compressor_t *zlib = calloc(1, sizeof(*zlib)); - compressor_t *base = (compressor_t *)zlib; - int ret; - - if (zlib == NULL) { - perror("creating zlib stream"); - return NULL; - } - - zlib->compress = compress; - zlib->block_size = block_size; - base->do_block = zlib_do_block; - base->destroy = zlib_destroy; - - if (compress) { - ret = deflateInit(&zlib->strm, Z_BEST_COMPRESSION); - } else { - ret = inflateInit(&zlib->strm); - } - - if (ret != Z_OK) { - fputs("internal error creating zlib stream\n", stderr); - free(zlib); - return NULL; - } - - return base; -} |