From: Christian P. <cp...@us...> - 2005-01-03 13:44:00
|
Update of /cvsroot/pclasses/pclasses2/include/pclasses/IO In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18256/include/pclasses/IO Added Files: ZLib.h Log Message: Added zlib compression support (decompression will follow...) --- NEW FILE: ZLib.h --- /*************************************************************************** * Copyright (C) 2004 by Christian Prochnow * * cp...@se... * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU Library General Public License as * * published by the Free Software Foundation; either version 2 of the * * License, or (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU Library General Public * * License along with this program; if not, write to the * * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ #ifndef P_IO_ZLib_h #define P_IO_ZLib_h #include <pclasses/Exception.h> #include <pclasses/IntTypes.h> #include <string> struct z_stream_s; typedef z_stream_s z_stream; namespace P { namespace IO { //! ZLib error class ZLibError: public RuntimeError { public: ZLibError(int err, const char* msg, const char* what, const SourceInfo& si); ~ZLibError(); int errorNo() const throw(); const std::string& msg() const throw(); private: int _err; std::string _msg; }; //! ZLib stream base class ZLibStream { public: ZLibStream(); virtual ~ZLibStream(); //! Number of bytes available to consume size_t bytesAvail() const throw(); //! Consume compressed data size_t read(char* buffer, size_t count) throw(ZLibError); //! Returns the crc32 UInt32 crc32() const throw(); protected: void put(const char* buffer, size_t count) throw(ZLibError); z_stream* _strm; char* _buffer; size_t _bufferSize; UInt32 _crc32; }; //! ZLib output (deflate) stream class ZLibOutputStream: public ZLibStream { public: ZLibOutputStream(int level = 6) throw(ZLibError); ~ZLibOutputStream() throw(); //! Deflate (compress) buffer into output buffer size_t deflate(const char* buffer, size_t count) throw(ZLibError); //! Finish compression and reset state bool finish() throw(ZLibError); //! Reset stream void reset() throw(ZLibError); private: void putHeader(); void putFooter(); enum State { Ready, AboutToFinish, Finished }; State _state; }; } // !namespace IO } // !namespace P #endif |