QuaZip quazip-1-4
QuaZIODevice Class Reference

A class to compress/decompress QIODevice. More...

#include <quaziodevice.h>

Inheritance diagram for QuaZIODevice:
Collaboration diagram for QuaZIODevice:

Public Member Functions

 QuaZIODevice (QIODevice *io, QObject *parent=nullptr)
 Constructor.
 
 ~QuaZIODevice () override
 Destructor.
 
virtual bool flush ()
 Flushes data waiting to be written.
 
bool open (QIODevice::OpenMode mode) override
 Opens the device.
 
void close () override
 Closes this device, but not the underlying one.
 
QIODevice * getIoDevice () const
 Returns the underlying device.
 
bool isSequential () const override
 Returns true.
 
bool atEnd () const override
 Returns true iff the end of the compressed stream is reached.
 
qint64 bytesAvailable () const override
 Returns the number of the bytes buffered.
 

Protected Member Functions

qint64 readData (char *data, qint64 maxSize) override
 Implementation of QIODevice::readData().
 
qint64 writeData (const char *data, qint64 maxSize) override
 Implementation of QIODevice::writeData().
 

Friends

class QuaZIODevicePrivate
 

Detailed Description

A class to compress/decompress QIODevice.

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.

Constructor & Destructor Documentation

◆ QuaZIODevice()

QuaZIODevice::QuaZIODevice ( QIODevice * io,
QObject * parent = nullptr )

Constructor.

Parameters
ioThe QIODevice to read/write.
parentThe parent object, as per QObject logic.

Member Function Documentation

◆ flush()

bool QuaZIODevice::flush ( )
virtual

Flushes data waiting to be written.

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:

QuaZIODevice dev(&sock);
dev.open(QIODevice::Write);
dev.write(yourDataGoesHere);
dev.flush();
sock->flush(); // this actually sends data to network
A class to compress/decompress QIODevice.
Definition quaziodevice.h:41

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.

◆ open()

bool QuaZIODevice::open ( QIODevice::OpenMode mode)
override

Opens the device.

Parameters
modeNeither QIODevice::ReadWrite nor QIODevice::Append are not supported.

◆ close()

void QuaZIODevice::close ( )
override

Closes this device, but not the underlying one.

The underlying QIODevice is not closed in case you want to write something else to it.

Referenced by ~QuaZIODevice().


The documentation for this class was generated from the following files: