aboutsummaryrefslogtreecommitdiff
path: root/lib/io/uncompress/istream_compressor.c
diff options
context:
space:
mode:
authorDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2022-06-26 22:51:27 +0200
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2022-07-08 19:17:35 +0200
commit359d71e90050a8b83f7bc7d2ecd4ff29c477cc22 (patch)
treedf2b7a585b78e6776446d4ca9be62a22db27f0a7 /lib/io/uncompress/istream_compressor.c
parent2087cc237cd0fe1ed29ebf891648bacb46f4833b (diff)
Cleanup: rename libfstream to libio, split headers
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'lib/io/uncompress/istream_compressor.c')
-rw-r--r--lib/io/uncompress/istream_compressor.c69
1 files changed, 69 insertions, 0 deletions
diff --git a/lib/io/uncompress/istream_compressor.c b/lib/io/uncompress/istream_compressor.c
new file mode 100644
index 0000000..ab9ad8b
--- /dev/null
+++ b/lib/io/uncompress/istream_compressor.c
@@ -0,0 +1,69 @@
+/* SPDX-License-Identifier: GPL-3.0-or-later */
+/*
+ * istream_compressor.c
+ *
+ * Copyright (C) 2019 David Oberhollenzer <goliath@infraroot.at>
+ */
+#include "../internal.h"
+
+static const char *comp_get_filename(istream_t *strm)
+{
+ istream_comp_t *comp = (istream_comp_t *)strm;
+
+ return comp->wrapped->get_filename(comp->wrapped);
+}
+
+static void comp_destroy(sqfs_object_t *obj)
+{
+ istream_comp_t *comp = (istream_comp_t *)obj;
+
+ comp->cleanup(comp);
+ sqfs_destroy(comp->wrapped);
+ free(comp);
+}
+
+istream_t *istream_compressor_create(istream_t *strm, int comp_id)
+{
+ istream_comp_t *comp = NULL;
+ sqfs_object_t *obj;
+ istream_t *base;
+
+ switch (comp_id) {
+ case IO_COMPRESSOR_GZIP:
+#ifdef WITH_GZIP
+ comp = istream_gzip_create(strm->get_filename(strm));
+#endif
+ break;
+ case IO_COMPRESSOR_XZ:
+#ifdef WITH_XZ
+ comp = istream_xz_create(strm->get_filename(strm));
+#endif
+ break;
+ case IO_COMPRESSOR_ZSTD:
+#if defined(WITH_ZSTD) && defined(HAVE_ZSTD_STREAM)
+ comp = istream_zstd_create(strm->get_filename(strm));
+#endif
+ break;
+ case IO_COMPRESSOR_BZIP2:
+#ifdef WITH_BZIP2
+ comp = istream_bzip2_create(strm->get_filename(strm));
+#endif
+ break;
+ default:
+ break;
+ }
+
+ if (comp == NULL)
+ return NULL;
+
+ comp->wrapped = strm;
+
+ base = (istream_t *)comp;
+ base->get_filename = comp_get_filename;
+ base->buffer = comp->uncompressed;
+ base->eof = false;
+
+ obj = (sqfs_object_t *)comp;
+ obj->destroy = comp_destroy;
+ return base;
+}