summaryrefslogtreecommitdiff
path: root/libnbtplusplus/include/io/zlib_streambuf.h
diff options
context:
space:
mode:
authorMehmet Samet Duman <yongdohyun@projecttick.org>2026-04-02 19:56:58 +0300
committerMehmet Samet Duman <yongdohyun@projecttick.org>2026-04-02 19:56:58 +0300
commita4b5ffbaadb591066e2a97f8d450fb1d93e56a6e (patch)
treeae7c5841f264eea66484f9a413111ce012fa7a86 /libnbtplusplus/include/io/zlib_streambuf.h
parent7fb132859fda54aa96bc9dd46d302b343eeb5a02 (diff)
parent1a0ffe372f4da8408c5d08a36013536a3396b9e6 (diff)
downloadProject-Tick-a4b5ffbaadb591066e2a97f8d450fb1d93e56a6e.tar.gz
Project-Tick-a4b5ffbaadb591066e2a97f8d450fb1d93e56a6e.zip
Add 'libnbtplusplus/' from commit '1a0ffe372f4da8408c5d08a36013536a3396b9e6'
git-subtree-dir: libnbtplusplus git-subtree-mainline: 7fb132859fda54aa96bc9dd46d302b343eeb5a02 git-subtree-split: 1a0ffe372f4da8408c5d08a36013536a3396b9e6
Diffstat (limited to 'libnbtplusplus/include/io/zlib_streambuf.h')
-rw-r--r--libnbtplusplus/include/io/zlib_streambuf.h51
1 files changed, 51 insertions, 0 deletions
diff --git a/libnbtplusplus/include/io/zlib_streambuf.h b/libnbtplusplus/include/io/zlib_streambuf.h
new file mode 100644
index 0000000000..91a660b9f2
--- /dev/null
+++ b/libnbtplusplus/include/io/zlib_streambuf.h
@@ -0,0 +1,51 @@
+/*
+ * SPDX-FileCopyrightText: 2013, 2015 ljfa-ag <ljfa-ag@web.de>
+ *
+ * SPDX-License-Identifier: LGPL-3.0-or-later
+ */
+
+#ifndef ZLIB_STREAMBUF_H_INCLUDED
+#define ZLIB_STREAMBUF_H_INCLUDED
+
+#include <stdexcept>
+#include <streambuf>
+#include <vector>
+#include <zlib.h>
+#include "nbt_export.h"
+
+namespace zlib
+{
+
+ /// Exception thrown in case zlib encounters a problem
+ class NBT_EXPORT zlib_error : public std::runtime_error
+ {
+ public:
+ const int errcode;
+
+ zlib_error(const char* msg, int errcode)
+ : std::runtime_error(msg ? std::string(zError(errcode)) + ": " + msg
+ : zError(errcode)),
+ errcode(errcode)
+ {
+ }
+ };
+
+ /// Base class for deflate_streambuf and inflate_streambuf
+ class zlib_streambuf : public std::streambuf
+ {
+ protected:
+ std::vector<char> in;
+ std::vector<char> out;
+ z_stream zstr;
+
+ explicit zlib_streambuf(size_t bufsize) : in(bufsize), out(bufsize)
+ {
+ zstr.zalloc = Z_NULL;
+ zstr.zfree = Z_NULL;
+ zstr.opaque = Z_NULL;
+ }
+ };
+
+} // namespace zlib
+
+#endif // ZLIB_STREAMBUF_H_INCLUDED