From 258f8533164281e2288745d75a1c33997400a94c Mon Sep 17 00:00:00 2001 From: Pixel Date: Mon, 12 Dec 2011 08:43:16 -0800 Subject: Adding ZHandle class. It needs a unit test though. --- includes/ZHandle.h | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 includes/ZHandle.h (limited to 'includes/ZHandle.h') 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 +#include + +namespace Balau { + +class ZStream : public Handle { + public: + typedef enum { + ZLIB, + GZIP, + RAW, + } header_t; + ZStream(const IO & 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 m_h; + z_stream m_zin, m_zout; + bool m_detached, m_closed, m_eof; + String m_name; + uint8_t * m_in; +}; + +}; -- cgit v1.2.3