zlibbytearray.h

Go to the documentation of this file.
00001 /*
00002 **  This file is part of Vidalia, and is subject to the license terms in the
00003 **  LICENSE file, found in the top level directory of this distribution. If you
00004 **  did not receive the LICENSE file with this file, you may obtain it from the
00005 **  Vidalia source package distributed by the Vidalia Project at
00006 **  http://www.vidalia-project.net/. No part of Vidalia, including this file,
00007 **  may be copied, modified, propagated, or distributed except according to the
00008 **  terms described in the LICENSE file.
00009 **
00010 **                     *       *       *
00011 ** 
00012 **  Zlib support in this class is derived from Tor's torgzip.[ch].
00013 **  Tor is distributed under this license:
00014 ** 
00015 **    Copyright (c) 2001-2004, Roger Dingledine
00016 **    Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson
00017 **
00018 **   Redistribution and use in source and binary forms, with or without
00019 **   modification, are permitted provided that the following conditions are
00020 **   met:
00021 **
00022 **     * Redistributions of source code must retain the above copyright
00023 **       notice, this list of conditions and the following disclaimer.
00024 **
00025 **     * Redistributions in binary form must reproduce the above
00026 **       copyright notice, this list of conditions and the following disclaimer
00027 **       in the documentation and/or other materials provided with the
00028 **       distribution.
00029 ** 
00030 **     * Neither the names of the copyright owners nor the names of its
00031 **       contributors may be used to endorse or promote products derived from
00032 **       this software without specific prior written permission.
00033 **
00034 **    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00035 **    "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00036 **    LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
00037 **    A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
00038 **    OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
00039 **    SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
00040 **    LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00041 **    DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
00042 **    THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00043 **    (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00044 **    OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00045 */
00046 
00047 /*
00048 ** \file zlibbytearray.h
00049 ** \version $Id: zlibbytearray.h 2362 2008-02-29 04:30:11Z edmanm $
00050 ** \brief Wrapper around QByteArray that adds compression capabilities
00051 */
00052 
00053 #ifndef _ZLIBBYTEARRAY_H
00054 #define _ZLIBBYTEARRAY_H
00055 
00056 #include <QByteArray>
00057 #include <QString>
00058 
00059 
00060 class ZlibByteArray : public QByteArray
00061 {
00062 public:
00063   /** Available compression methods. */
00064   enum CompressionMethod {
00065     None,   /**< No compression method. */
00066     Gzip,   /**< Gzip compression method. */
00067     Zlib    /**< Zlib compression method. */
00068   };
00069   
00070   /** Constructor. */
00071   ZlibByteArray(QByteArray data); 
00072   
00073   /** Compresses the current contents of this object using <b>method</b>. */
00074   QByteArray compress(const CompressionMethod method = Zlib,
00075                       QString *errmsg = 0) const;
00076   /** Compreses the contents of <b>in</b> using <b>method</b>. */
00077   static QByteArray compress(const QByteArray in, 
00078                              const CompressionMethod method = Zlib,
00079                              QString *errmsg = 0);
00080   /** Uncompresses the current contents of this object using <b>method</b>. */
00081   QByteArray uncompress(CompressionMethod method = Zlib,
00082                         QString *errmsg = 0) const;
00083   /** Uncompresses the contents of <b>in</b> using <b>method</b>. */
00084   static QByteArray uncompress(const QByteArray in,
00085                                const CompressionMethod method = Zlib,
00086                                QString *errmsg = 0);
00087 
00088   /** Returns true if the Zlib compression library is available and usable. */
00089   static bool isZlibAvailable();
00090   /** Returns true iff we support gzip-based compression. Otherwise, we need to
00091     * use zlib. */
00092   static bool isGzipSupported();
00093 
00094 private:
00095   /** Return the 'bits' value to tell zlib to use <b>method</b>.*/
00096   static int methodBits(CompressionMethod method);
00097   /** Returns a string description of <b>method</b>. */
00098   static QString methodString(CompressionMethod method);
00099 };
00100 
00101 #endif
00102 

Generated on 28 Dec 2009 for Vidalia by  doxygen 1.6.1