summaryrefslogtreecommitdiff
path: root/includes
diff options
context:
space:
mode:
Diffstat (limited to 'includes')
-rw-r--r--includes/ZHandle.h37
1 files changed, 37 insertions, 0 deletions
diff --git a/includes/ZHandle.h b/includes/ZHandle.h
new file mode 100644
index 0000000..63da59a
--- /dev/null
+++ b/includes/ZHandle.h
@@ -0,0 +1,37 @@
+#pragma once
+
+#include <zlib.h>
+#include <Handle.h>
+
+namespace Balau {
+
+class ZStream : public Handle {
+ public:
+ typedef enum {
+ ZLIB,
+ GZIP,
+ RAW,
+ } header_t;
+ ZStream(const IO<Handle> & h, int level = Z_BEST_COMPRESSION, header_t header = ZLIB);
+ virtual void close() throw (GeneralException);
+ virtual bool isClosed();
+ virtual bool isEOF();
+ virtual bool canRead();
+ virtual bool canWrite();
+ virtual const char * getName();
+ virtual ssize_t read(void * buf, size_t count) throw (GeneralException);
+ virtual ssize_t write(const void * buf, size_t count) throw (GeneralException);
+ virtual off_t getSize();
+ void detach() { m_detached = true; }
+ void flush() { doFlush(false); }
+ private:
+ void finish() { doFlush(true); }
+ void doFlush(bool finish);
+ IO<Handle> m_h;
+ z_stream m_zin, m_zout;
+ bool m_detached, m_closed, m_eof;
+ String m_name;
+ uint8_t * m_in;
+};
+
+};