A class to compress/decompress QIODevice.
More...
#include <src/ckb/quazip/quaziodevice.h>
|
virtual qint64 | readData (char *data, qint64 maxSize) |
| Implementation of QIODevice::readData(). More...
|
|
virtual qint64 | writeData (const char *data, qint64 maxSize) |
| Implementation of QIODevice::writeData(). More...
|
|
This class can be used to compress any data written to QIODevice or decompress it back. Compressing data sent over a QTcpSocket is a good example.
Definition at line 41 of file quaziodevice.h.
- Parameters
-
Definition at line 123 of file quaziodevice.cpp.
125 d(
new QuaZIODevicePrivate(io))
127 connect(io, SIGNAL(readyRead()), SIGNAL(readyRead()));
QuaZIODevice::~QuaZIODevice |
( |
| ) |
|
Definition at line 130 of file quaziodevice.cpp.
References close(), and d.
virtual void close()
Closes this device, but not the underlying one.
void QuaZIODevice::close |
( |
| ) |
|
|
virtual |
The underlying QIODevice is not closed in case you want to write something else to it.
Definition at line 169 of file quaziodevice.cpp.
References d, and flush().
Referenced by ~QuaZIODevice().
171 if ((openMode() & QIODevice::ReadOnly) != 0) {
172 if (inflateEnd(&
d->zins) != Z_OK) {
173 setErrorString(
d->zins.msg);
176 if ((openMode() & QIODevice::WriteOnly) != 0) {
178 if (deflateEnd(&
d->zouts) != Z_OK) {
179 setErrorString(
d->zouts.msg);
virtual bool flush()
Flushes data waiting to be written.
bool QuaZIODevice::flush |
( |
| ) |
|
|
virtual |
Unfortunately, as QIODevice doesn't support flush() by itself, the only thing this method does is write the compressed data into the device using Z_SYNC_FLUSH mode. If you need the compressed data to actually be flushed from the buffer of the underlying QIODevice, you need to call its flush() method as well, providing it supports it (like QTcpSocket does). Example:
dev.open(QIODevice::Write);
dev.write(yourDataGoesHere);
dev.flush();
sock->flush();
This may change in the future versions of QuaZIP by implementing an ugly hack: trying to cast the QIODevice using qobject_cast to known flush()-supporting subclasses, and calling flush if the resulting pointer is not zero.
Definition at line 281 of file quaziodevice.cpp.
References d, and QUAZIO_OUTBUFSIZE.
Referenced by close().
284 if (
d->doFlush(error) < 0) {
285 setErrorString(error);
289 if (
d->outBufPos <
d->outBufSize)
292 d->zouts.next_in = &c;
293 d->zouts.avail_in = 0;
295 d->zouts.next_out = (Bytef *)
d->outBuf;
297 switch (deflate(&
d->zouts, Z_SYNC_FLUSH)) {
299 d->outBufSize = (
char *)
d->zouts.next_out -
d->outBuf;
300 if (
d->doFlush(error) < 0) {
301 setErrorString(error);
304 if (
d->outBufPos <
d->outBufSize)
310 setErrorString(QString::fromLocal8Bit(
d->zouts.msg));
313 }
while (
d->zouts.avail_out == 0);
#define QUAZIO_OUTBUFSIZE
QIODevice * QuaZIODevice::getIoDevice |
( |
| ) |
const |
bool QuaZIODevice::isSequential |
( |
| ) |
const |
|
virtual |
bool QuaZIODevice::open |
( |
QIODevice::OpenMode |
mode | ) |
|
|
virtual |
- Parameters
-
mode | Neither QIODevice::ReadWrite nor QIODevice::Append are not supported. |
Definition at line 142 of file quaziodevice.cpp.
References d.
144 if ((mode & QIODevice::Append) != 0) {
145 setErrorString(trUtf8(
"QIODevice::Append is not supported for"
149 if ((mode & QIODevice::ReadWrite) == QIODevice::ReadWrite) {
150 setErrorString(trUtf8(
"QIODevice::ReadWrite is not supported for"
154 if ((mode & QIODevice::ReadOnly) != 0) {
155 if (inflateInit(&
d->zins) != Z_OK) {
156 setErrorString(
d->zins.msg);
160 if ((mode & QIODevice::WriteOnly) != 0) {
161 if (deflateInit(&
d->zouts, Z_DEFAULT_COMPRESSION) != Z_OK) {
162 setErrorString(
d->zouts.msg);
166 return QIODevice::open(mode);
qint64 QuaZIODevice::readData |
( |
char * |
data, |
|
|
qint64 |
maxSize |
|
) |
| |
|
protectedvirtual |
Definition at line 185 of file quaziodevice.cpp.
References d, and QUAZIO_INBUFSIZE.
188 while (read < maxSize) {
189 if (
d->inBufPos ==
d->inBufSize) {
192 if (
d->inBufSize == -1) {
194 setErrorString(
d->io->errorString());
197 if (
d->inBufSize == 0)
200 while (read < maxSize && d->inBufPos < d->inBufSize) {
201 d->zins.next_in = (Bytef *) (
d->inBuf +
d->inBufPos);
202 d->zins.avail_in =
d->inBufSize -
d->inBufPos;
203 d->zins.next_out = (Bytef *) (data + read);
204 d->zins.avail_out = (uInt) (maxSize - read);
206 switch (inflate(&
d->zins, Z_SYNC_FLUSH)) {
208 read = (
char *)
d->zins.next_out - data;
209 d->inBufPos = (
char *)
d->zins.next_in -
d->inBuf;
212 read = (
char *)
d->zins.next_out - data;
213 d->inBufPos = (
char *)
d->zins.next_in -
d->inBuf;
217 qWarning(
"Z_BUF_ERROR detected with %d/%d in/out, weird",
218 d->zins.avail_in,
d->zins.avail_out);
221 memmove(
d->inBuf,
d->inBuf +
d->inBufPos,
d->inBufSize -
d->inBufPos);
222 d->inBufSize -=
d->inBufPos;
226 setErrorString(
d->io->errorString());
231 d->inBufSize += more;
234 setErrorString(QString::fromLocal8Bit(
d->zins.msg));
239 #ifdef QUAZIP_ZIODEVICE_DEBUG_INPUT
240 indebug.write(data, read);
qint64 QuaZIODevice::writeData |
( |
const char * |
data, |
|
|
qint64 |
maxSize |
|
) |
| |
|
protectedvirtual |
Definition at line 245 of file quaziodevice.cpp.
References d, and QUAZIO_OUTBUFSIZE.
249 if (
d->doFlush(error) == -1) {
250 setErrorString(error);
253 while (written < maxSize) {
255 if (
d->outBufPos <
d->outBufSize)
257 d->zouts.next_in = (Bytef *) (data + written);
258 d->zouts.avail_in = (uInt) (maxSize - written);
259 d->zouts.next_out = (Bytef *)
d->outBuf;
261 switch (deflate(&
d->zouts, Z_NO_FLUSH)) {
263 written = (
char *)
d->zouts.next_in - data;
264 d->outBufSize = (
char *)
d->zouts.next_out -
d->outBuf;
267 setErrorString(QString::fromLocal8Bit(
d->zouts.msg));
270 if (
d->doFlush(error) == -1) {
271 setErrorString(error);
275 #ifdef QUAZIP_ZIODEVICE_DEBUG_OUTPUT
276 debug.write(data, written);
#define QUAZIO_OUTBUFSIZE
QuaZIODevicePrivate* QuaZIODevice::d |
|
private |
The documentation for this class was generated from the following files: