zutils.h

Go to the documentation of this file.
00001 /**
00002  *  Copyright (C) 2004-2005 Alo Sarv <madcat_@users.sourceforge.net>
00003  *
00004  *  This program is free software; you can redistribute it and/or modify
00005  *  it under the terms of the GNU General Public License as published by
00006  *  the Free Software Foundation; either version 2 of the License, or
00007  *  (at your option) any later version.
00008  *
00009  *  This program is distributed in the hope that it will be useful,
00010  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  *  GNU General Public License for more details.
00013  *
00014  *  You should have received a copy of the GNU General Public License
00015  *  along with this program; if not, write to the Free Software
00016  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00017  */
00018 
00019 /** \file zutils.h
00020  * C++ wrapper functions/classes for compression-related functionality
00021  */
00022 
00023 #ifndef __ZUTILS_H__
00024 #define __ZUTILS_H__
00025 
00026 #include <hn/osdep.h>
00027 
00028 //! @name ZLIB compression/decompression methods
00029 namespace Zlib {
00030 
00031 /**
00032  * Compresses the passed data, returning compressed data.
00033  *
00034  * @param input         Data to be compressed
00035  * @return              Compressed data. May be empty if compression fails.
00036  */
00037 extern std::string compress(const std::string &input);
00038 
00039 /**
00040  * Decompresses passed data.
00041  *
00042  * @param input         Data to be uncompressed
00043  * @param bufsize       Suggested buffer size. If left at default value, the
00044  *                      method attempts to guess the internal buffer size for
00045  *                      unpacking itself.
00046  * @return              Unpacked data, or empty string if something goes wrong
00047  *
00048  * \throws std::runtime_error if decompression fails
00049  *
00050  * \note This function may call itself recursivly if the destination buffer size
00051  *       was not big enough to unpack the data (thus the second parameter also).
00052  *       The recursion ends either when the unpacking succeeds, or when
00053  *       destination buffer size exceeds 1MB. If you want to decompress data
00054  *       resulting in larger amount of unpacket data than 1MB, explicitly
00055  *       specify the buffer size as parameter.
00056  */
00057 extern std::string decompress(const std::string &input, uint32_t bufsize = 0);
00058 
00059 }
00060 
00061 #endif