aboutsummaryrefslogtreecommitdiff
path: root/lib/io/compress/ostream_compressor.c
diff options
context:
space:
mode:
authorDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2022-12-13 09:15:19 +0100
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2023-01-19 16:24:56 +0100
commit551dd3879c288a2b6b6fbaca5c09c04fbe994ff4 (patch)
treef3437139699edffd034168999854258f30c4023b /lib/io/compress/ostream_compressor.c
parent722ecf27eaf83685dfc6e92adc9d66f0107da5ea (diff)
Split stream compression out of libio
Move it to a separate libxfrm library, where it can be independently tested as well. The bulk of the new code is also mainly test cases for the compressors. Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'lib/io/compress/ostream_compressor.c')
-rw-r--r--lib/io/compress/ostream_compressor.c106
1 files changed, 0 insertions, 106 deletions
diff --git a/lib/io/compress/ostream_compressor.c b/lib/io/compress/ostream_compressor.c
deleted file mode 100644
index a5f16d5..0000000
--- a/lib/io/compress/ostream_compressor.c
+++ /dev/null
@@ -1,106 +0,0 @@
-/* SPDX-License-Identifier: GPL-3.0-or-later */
-/*
- * ostream_compressor.c
- *
- * Copyright (C) 2019 David Oberhollenzer <goliath@infraroot.at>
- */
-#include "../internal.h"
-
-static int comp_append(ostream_t *strm, const void *data, size_t size)
-{
- ostream_comp_t *comp = (ostream_comp_t *)strm;
- size_t diff;
-
- while (size > 0) {
- if (comp->inbuf_used >= BUFSZ) {
- if (comp->flush_inbuf(comp, false))
- return -1;
- }
-
- diff = BUFSZ - comp->inbuf_used;
-
- if (diff > size)
- diff = size;
-
- memcpy(comp->inbuf + comp->inbuf_used, data, diff);
-
- comp->inbuf_used += diff;
- data = (const char *)data + diff;
- size -= diff;
- }
-
- return 0;
-}
-
-static int comp_flush(ostream_t *strm)
-{
- ostream_comp_t *comp = (ostream_comp_t *)strm;
-
- if (comp->inbuf_used > 0) {
- if (comp->flush_inbuf(comp, true))
- return -1;
- }
-
- return comp->wrapped->flush(comp->wrapped);
-}
-
-static const char *comp_get_filename(ostream_t *strm)
-{
- ostream_comp_t *comp = (ostream_comp_t *)strm;
-
- return comp->wrapped->get_filename(comp->wrapped);
-}
-
-static void comp_destroy(sqfs_object_t *obj)
-{
- ostream_comp_t *comp = (ostream_comp_t *)obj;
-
- comp->cleanup(comp);
- sqfs_drop(comp->wrapped);
- free(comp);
-}
-
-ostream_t *ostream_compressor_create(ostream_t *strm, int comp_id)
-{
- ostream_comp_t *comp = NULL;
- ostream_t *base;
-
- switch (comp_id) {
- case IO_COMPRESSOR_GZIP:
-#ifdef WITH_GZIP
- comp = ostream_gzip_create(strm->get_filename(strm));
-#endif
- break;
- case IO_COMPRESSOR_XZ:
-#ifdef WITH_XZ
- comp = ostream_xz_create(strm->get_filename(strm));
-#endif
- break;
- case IO_COMPRESSOR_ZSTD:
-#if defined(WITH_ZSTD) && defined(HAVE_ZSTD_STREAM)
- comp = ostream_zstd_create(strm->get_filename(strm));
-#endif
- break;
- case IO_COMPRESSOR_BZIP2:
-#ifdef WITH_BZIP2
- comp = ostream_bzip2_create(strm->get_filename(strm));
-#endif
- break;
- default:
- break;
- }
-
- if (comp == NULL)
- return NULL;
-
- sqfs_object_init(comp, comp_destroy, NULL);
-
- comp->wrapped = sqfs_grab(strm);
- comp->inbuf_used = 0;
-
- base = (ostream_t *)comp;
- base->append = comp_append;
- base->flush = comp_flush;
- base->get_filename = comp_get_filename;
- return base;
-}