Vidalia 0.3.1
ZlibByteArray.h
Go to the documentation of this file.
1/*
2** This file is part of Vidalia, and is subject to the license terms in the
3** LICENSE file, found in the top level directory of this distribution. If you
4** did not receive the LICENSE file with this file, you may obtain it from the
5** Vidalia source package distributed by the Vidalia Project at
6** http://www.torproject.org/projects/vidalia.html. No part of Vidalia,
7** including this file, may be copied, modified, propagated, or distributed
8** except according to the terms described in the LICENSE file.
9**
10** * * *
11**
12** Zlib support in this class is derived from Tor's torgzip.[ch].
13** Tor is distributed under this license:
14**
15** Copyright (c) 2001-2004, Roger Dingledine
16** Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson
17**
18** Redistribution and use in source and binary forms, with or without
19** modification, are permitted provided that the following conditions are
20** met:
21**
22** * Redistributions of source code must retain the above copyright
23** notice, this list of conditions and the following disclaimer.
24**
25** * Redistributions in binary form must reproduce the above
26** copyright notice, this list of conditions and the following disclaimer
27** in the documentation and/or other materials provided with the
28** distribution.
29**
30** * Neither the names of the copyright owners nor the names of its
31** contributors may be used to endorse or promote products derived from
32** this software without specific prior written permission.
33**
34** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
35** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
36** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
37** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
38** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
39** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
40** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
41** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
42** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
43** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
44** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
45*/
46
47/*
48** \file ZlibByteArray.h
49** \brief Wrapper around QByteArray that adds compression capabilities
50*/
51
52#ifndef _ZLIBBYTEARRAY_H
53#define _ZLIBBYTEARRAY_H
54
55#include <QByteArray>
56#include <QString>
57
58
59class ZlibByteArray : public QByteArray
60{
61public:
62 /** Available compression methods. */
64 None, /**< No compression method. */
65 Gzip, /**< Gzip compression method. */
66 Zlib /**< Zlib compression method. */
67 };
68
69 /** Constructor. */
70 ZlibByteArray(QByteArray data);
71
72 /** Compresses the current contents of this object using <b>method</b>. */
73 QByteArray compress(const CompressionMethod method = Zlib,
74 QString *errmsg = 0) const;
75 /** Compreses the contents of <b>in</b> using <b>method</b>. */
76 static QByteArray compress(const QByteArray in,
77 const CompressionMethod method = Zlib,
78 QString *errmsg = 0);
79 /** Uncompresses the current contents of this object using <b>method</b>. */
80 QByteArray uncompress(CompressionMethod method = Zlib,
81 QString *errmsg = 0) const;
82 /** Uncompresses the contents of <b>in</b> using <b>method</b>. */
83 static QByteArray uncompress(const QByteArray in,
84 const CompressionMethod method = Zlib,
85 QString *errmsg = 0);
86
87 /** Returns true if the Zlib compression library is available and usable. */
88 static bool isZlibAvailable();
89 /** Returns true iff we support gzip-based compression. Otherwise, we need to
90 * use zlib. */
91 static bool isGzipSupported();
92
93private:
94 /** Return the 'bits' value to tell zlib to use <b>method</b>.*/
95 static int methodBits(CompressionMethod method);
96 /** Returns a string description of <b>method</b>. */
97 static QString methodString(CompressionMethod method);
98};
99
100#endif
101
QByteArray compress(const CompressionMethod method=Zlib, QString *errmsg=0) const
static bool isZlibAvailable()
static QString methodString(CompressionMethod method)
static bool isGzipSupported()
ZlibByteArray(QByteArray data)
QByteArray uncompress(CompressionMethod method=Zlib, QString *errmsg=0) const
static int methodBits(CompressionMethod method)