summaryrefslogtreecommitdiff
path: root/includes/ZHandle.h
diff options
context:
space:
mode:
authorPixel <pixel@nobis-crew.org>2011-12-12 08:43:16 -0800
committerPixel <pixel@nobis-crew.org>2011-12-12 08:43:16 -0800
commit258f8533164281e2288745d75a1c33997400a94c (patch)
treeb2844e12f8f4adbebd18b1d32c2a78e15cc39f8a /includes/ZHandle.h
parentbd35da4e12bae00ded027c290b1c6757334f67de (diff)
Adding ZHandle class. It needs a unit test though.
Diffstat (limited to 'includes/ZHandle.h')
-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;
+};
+
+};