zlibbytearray.h

Go to the documentation of this file.
00001 /****************************************************************
00002  *  Vidalia is distributed under the following license:
00003  *
00004  *  Copyright (C) 2007,  Matt Edman, Justin Hipple
00005  *
00006  *  This program is free software; you can redistribute it and/or
00007  *  modify it under the terms of the GNU General Public License
00008  *  as published by the Free Software Foundation; either version 2
00009  *  of the License, or (at your option) any later version.
00010  *
00011  *  This program is distributed in the hope that it will be useful,
00012  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  *  GNU General Public License for more details.
00015  *
00016  *  You should have received a copy of the GNU General Public License
00017  *  along with this program; if not, write to the Free Software
00018  *  Foundation, Inc., 51 Franklin Street, Fifth Floor,
00019  *  Boston, MA  02110-1301, USA.
00020  * 
00021  *                     *       *       *
00022  * 
00023  *  Zlib support in this class is derived from Tor's torgzip.[ch].
00024  *  Tor is distributed under this license:
00025  * 
00026  *    Copyright (c) 2001-2004, Roger Dingledine
00027  *    Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson
00028  *
00029  *   Redistribution and use in source and binary forms, with or without
00030  *   modification, are permitted provided that the following conditions are
00031  *   met:
00032  *
00033  *     * Redistributions of source code must retain the above copyright
00034  *       notice, this list of conditions and the following disclaimer.
00035  *
00036  *     * Redistributions in binary form must reproduce the above
00037  *       copyright notice, this list of conditions and the following disclaimer
00038  *       in the documentation and/or other materials provided with the
00039  *       distribution.
00040  * 
00041  *     * Neither the names of the copyright owners nor the names of its
00042  *       contributors may be used to endorse or promote products derived from
00043  *       this software without specific prior written permission.
00044  *
00045  *    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00046  *    "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00047  *    LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
00048  *    A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
00049  *    OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
00050  *    SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
00051  *    LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00052  *    DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
00053  *    THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00054  *    (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00055  *    OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00056  ****************************************************************/
00057 
00058 /**
00059  * \file zlibbytearray.h
00060  * \version $Id: zlibbytearray.h 1618 2007-01-29 00:07:03Z edmanm $
00061  * \brief Wrapper around QByteArray that adds compression capabilities
00062  */
00063 
00064 #ifndef _ZLIBBYTEARRAY_H
00065 #define _ZLIBBYTEARRAY_H
00066 
00067 #include <QByteArray>
00068 #include <QString>
00069 
00070 
00071 class ZlibByteArray : public QByteArray
00072 {
00073 public:
00074   /** Available compression methods. */
00075   enum CompressionMethod {
00076     None,   /**< No compression method. */
00077     Gzip,   /**< Gzip compression method. */
00078     Zlib    /**< Zlib compression method. */
00079   };
00080   
00081   /** Constructor. */
00082   ZlibByteArray(QByteArray data); 
00083   
00084   /** Compresses the current contents of this object using <b>method</b>. */
00085   QByteArray compress(const CompressionMethod method = Zlib,
00086                       QString *errmsg = 0) const;
00087   /** Compreses the contents of <b>in</b> using <b>method</b>. */
00088   static QByteArray compress(const QByteArray in, 
00089                              const CompressionMethod method = Zlib,
00090                              QString *errmsg = 0);
00091   /** Uncompresses the current contents of this object using <b>method</b>. */
00092   QByteArray uncompress(CompressionMethod method = Zlib,
00093                         QString *errmsg = 0) const;
00094   /** Uncompresses the contents of <b>in</b> using <b>method</b>. */
00095   static QByteArray uncompress(const QByteArray in,
00096                                const CompressionMethod method = Zlib,
00097                                QString *errmsg = 0);
00098 
00099   /** Returns true if the Zlib compression library is available and usable. */
00100   static bool isZlibAvailable();
00101   /** Returns true iff we support gzip-based compression. Otherwise, we need to
00102     * use zlib. */
00103   static bool isGzipSupported();
00104 
00105 private:
00106   /** Return the 'bits' value to tell zlib to use <b>method</b>.*/
00107   static int methodBits(CompressionMethod method);
00108   /** Returns a string description of <b>method</b>. */
00109   static QString methodString(CompressionMethod method);
00110 };
00111 
00112 #endif
00113 

Generated on Wed Sep 5 15:49:28 2007 for Vidalia by  doxygen 1.5.3