[1096] | 1 | #ifndef QUAZIP_QUAZIODEVICE_H
|
---|
| 2 | #define QUAZIP_QUAZIODEVICE_H
|
---|
| 3 |
|
---|
| 4 | /*
|
---|
| 5 | Copyright (C) 2005-2014 Sergey A. Tachenov
|
---|
| 6 |
|
---|
| 7 | This file is part of QuaZIP.
|
---|
| 8 |
|
---|
| 9 | QuaZIP is free software: you can redistribute it and/or modify
|
---|
| 10 | it under the terms of the GNU Lesser General Public License as published by
|
---|
| 11 | the Free Software Foundation, either version 2.1 of the License, or
|
---|
| 12 | (at your option) any later version.
|
---|
| 13 |
|
---|
| 14 | QuaZIP is distributed in the hope that it will be useful,
|
---|
| 15 | but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 17 | GNU Lesser General Public License for more details.
|
---|
| 18 |
|
---|
| 19 | You should have received a copy of the GNU Lesser General Public License
|
---|
| 20 | along with QuaZIP. If not, see <http://www.gnu.org/licenses/>.
|
---|
| 21 |
|
---|
| 22 | See COPYING file for the full LGPL text.
|
---|
| 23 |
|
---|
| 24 | Original ZIP package is copyrighted by Gilles Vollant and contributors,
|
---|
| 25 | see quazip/(un)zip.h files for details. Basically it's the zlib license.
|
---|
| 26 | */
|
---|
| 27 |
|
---|
| 28 | #include <QIODevice>
|
---|
| 29 | #include "quazip_global.h"
|
---|
| 30 |
|
---|
| 31 | #include <zlib.h>
|
---|
| 32 |
|
---|
| 33 | class QuaZIODevicePrivate;
|
---|
| 34 |
|
---|
| 35 | /// A class to compress/decompress QIODevice.
|
---|
| 36 | /**
|
---|
| 37 | This class can be used to compress any data written to QIODevice or
|
---|
| 38 | decompress it back. Compressing data sent over a QTcpSocket is a good
|
---|
| 39 | example.
|
---|
| 40 | */
|
---|
| 41 | class QUAZIP_EXPORT QuaZIODevice: public QIODevice {
|
---|
| 42 | Q_OBJECT
|
---|
| 43 | public:
|
---|
| 44 | /// Constructor.
|
---|
| 45 | /**
|
---|
| 46 | \param io The QIODevice to read/write.
|
---|
| 47 | \param parent The parent object, as per QObject logic.
|
---|
| 48 | */
|
---|
| 49 | QuaZIODevice(QIODevice *io, QObject *parent = NULL);
|
---|
| 50 | /// Destructor.
|
---|
| 51 | ~QuaZIODevice();
|
---|
| 52 | /// Flushes data waiting to be written.
|
---|
| 53 | /**
|
---|
| 54 | Unfortunately, as QIODevice doesn't support flush() by itself, the
|
---|
| 55 | only thing this method does is write the compressed data into the
|
---|
| 56 | device using Z_SYNC_FLUSH mode. If you need the compressed data to
|
---|
| 57 | actually be flushed from the buffer of the underlying QIODevice, you
|
---|
| 58 | need to call its flush() method as well, providing it supports it
|
---|
| 59 | (like QTcpSocket does). Example:
|
---|
| 60 | \code
|
---|
| 61 | QuaZIODevice dev(&sock);
|
---|
| 62 | dev.open(QIODevice::Write);
|
---|
| 63 | dev.write(yourDataGoesHere);
|
---|
| 64 | dev.flush();
|
---|
| 65 | sock->flush(); // this actually sends data to network
|
---|
| 66 | \endcode
|
---|
| 67 |
|
---|
| 68 | This may change in the future versions of QuaZIP by implementing an
|
---|
| 69 | ugly hack: trying to cast the QIODevice using qobject_cast to known
|
---|
| 70 | flush()-supporting subclasses, and calling flush if the resulting
|
---|
| 71 | pointer is not zero.
|
---|
| 72 | */
|
---|
| 73 | virtual bool flush();
|
---|
| 74 | /// Opens the device.
|
---|
| 75 | /**
|
---|
| 76 | \param mode Neither QIODevice::ReadWrite nor QIODevice::Append are
|
---|
| 77 | not supported.
|
---|
| 78 | */
|
---|
| 79 | virtual bool open(QIODevice::OpenMode mode);
|
---|
| 80 | /// Closes this device, but not the underlying one.
|
---|
| 81 | /**
|
---|
| 82 | The underlying QIODevice is not closed in case you want to write
|
---|
| 83 | something else to it.
|
---|
| 84 | */
|
---|
| 85 | virtual void close();
|
---|
| 86 | /// Returns the underlying device.
|
---|
| 87 | QIODevice *getIoDevice() const;
|
---|
| 88 | /// Returns true.
|
---|
| 89 | virtual bool isSequential() const;
|
---|
| 90 | /// Returns true iff the end of the compressed stream is reached.
|
---|
| 91 | virtual bool atEnd() const;
|
---|
| 92 | /// Returns the number of the bytes buffered.
|
---|
| 93 | virtual qint64 bytesAvailable() const;
|
---|
| 94 | protected:
|
---|
| 95 | /// Implementation of QIODevice::readData().
|
---|
| 96 | virtual qint64 readData(char *data, qint64 maxSize);
|
---|
| 97 | /// Implementation of QIODevice::writeData().
|
---|
| 98 | virtual qint64 writeData(const char *data, qint64 maxSize);
|
---|
| 99 | private:
|
---|
| 100 | QuaZIODevicePrivate *d;
|
---|
| 101 | };
|
---|
| 102 | #endif // QUAZIP_QUAZIODEVICE_H
|
---|