Home |
The QtIOCompressor class is a QIODevice that compresses data streams. More...
#include <QtIOCompressor>
Inherits QIODevice.
The QtIOCompressor class is a QIODevice that compresses data streams.
A QtIOCompressor object is constructed with a pointer to an underlying QIODevice. Data written to the QtIOCompressor object will be compressed before it is written to the underlying QIODevice. Similary, if you read from the QtIOCompressor object, the data will be read from the underlying device and then decompressed.
QtIOCompressor is a sequential device, which means that it does not support seeks or random access. Internally, QtIOCompressor uses the zlib library to compress and uncompress data.
Usage examples: Writing compressed data to a file:
QFile file("foo"); QtIOCompressor compressor(&file); compressor.open(QIODevice::WriteOnly); compressor.write(QByteArray() << "The quick brown fox"); compressor.close();
Reading compressed data from a file:
QFile file("foo"); QtIOCompressor compressor(&file); compressor.open(QIODevice::ReadOnly); const QByteArray text = compressor.readAll(); compressor.close();
QtIOCompressor can also read and write compressed data in different compressed formats, ref. StreamFormat. Use setStreamFormat() before open() to select format.
This enum specifies which stream format to use.
Constant | Value | Description |
---|---|---|
QtIOCompressor::ZlibFormat | 0 | : This is the default and has the smallest overhead. |
QtIOCompressor::GzipFormat | 1 | : This format is compatible with the gzip file format, but has more overhead than ZlibFormat. Note: requires zlib version 1.2.x or higher at runtime. |
QtIOCompressor::RawZipFormat | 2 | : This is compatible with the most common compression method of the data blocks contained in ZIP archives. Note: ZIP file headers are not read or generated, so setting this format, by itself, does not let QtIOCompressor read or write ZIP files. Ref. the ziplist example program. |
See also setStreamFormat().
Constructs a QtIOCompressor using the given device as the underlying device.
The allowed value range for compressionLevel is 0 to 9, where 0 means no compression and 9 means maximum compression. The default value is 6.
bufferSize specifies the size of the internal buffer used when reading from and writing to the underlying device. The default value is 65KB. Using a larger value allows for faster compression and deompression at the expense of memory usage.
Destroys the QtIOCompressor, closing it if neccesary.
Returns 1 if there might be data available for reading, or 0 if there is no data available.
There is unfortunately no way of knowing how much data there is available when dealing with compressed streams.
Also, since the remaining compressed data might be a part of the meta-data that ends the compressed stream (and therefore will yield no uncompressed data), you cannot assume that a read after getting a 1 from this function will return data.
Reimplemented from QIODevice.
Closes the QtIOCompressor, and also the underlying device if it was opened by QtIOCompressor.
Reimplemented from QIODevice.
See also open().
Flushes the internal buffer.
Each time you call flush, all data written to the QtIOCompressor is compressed and written to the underlying device. Calling this function can reduce the compression ratio. The underlying device is not flushed.
Calling this function when QtIOCompressor is in ReadOnly mode has no effect.
Returns true if the zlib library in use supports the gzip format, false otherwise.
Opens the QtIOCompressor in mode. Only ReadOnly and WriteOnly is supported. This functon will return false if you try to open in other modes.
If the underlying device is not opened, this function will open it in a suitable mode. If this happens the device will also be closed when close() is called.
If the underlying device is already opened, its openmode must be compatable with mode.
Returns true on success, false on error.
See also close().
Sets the format on the compressed stream to format.
See also streamFormat() and QtIOCompressor::StreamFormat.
Returns the format set on the compressed stream.
See also setStreamFormat() and QtIOCompressor::StreamFormat.
Copyright © 2009 Nokia Corporation and/or its subsidiary(-ies) | Trademarks | Qt Solutions |