KArchive 5.109.0
|
A class for reading and writing compressed data onto a device (e.g. More...
#include <KCompressionDevice>
Public Types | |
enum | CompressionType { GZip , BZip2 , Xz , None , Zstd } |
Public Member Functions | |
KCompressionDevice (const QString &fileName) | |
Constructs a KCompressionDevice for a given fileName . | |
KCompressionDevice (const QString &fileName, CompressionType type) | |
Constructs a KCompressionDevice for a given CompressionType (e.g. | |
KCompressionDevice (QIODevice *inputDevice, bool autoDeleteInputDevice, CompressionType type) | |
Constructs a KCompressionDevice for a given CompressionType (e.g. | |
~KCompressionDevice () override | |
Destructs the KCompressionDevice. | |
bool | atEnd () const override |
void | close () override |
Close after reading or writing. | |
CompressionType | compressionType () const |
The compression actually used by this device. | |
QFileDevice::FileError | error () const |
Returns the error code from the last failing operation. | |
bool | open (QIODevice::OpenMode mode) override |
Open for reading or writing. | |
bool | seek (qint64) override |
That one can be quite slow, when going back. | |
void | setOrigFileName (const QByteArray &fileName) |
For writing gzip compressed files only: set the name of the original file, to be used in the gzip header. | |
void | setSkipHeaders () |
Call this let this device skip the gzip headers when reading/writing. | |
Static Public Member Functions | |
static CompressionType | compressionTypeForMimeType (const QString &mimetype) |
Returns the compression type for the given MIME type, if possible. | |
static KFilterBase * | filterForCompressionType (CompressionType type) |
Call this to create the appropriate filter for the CompressionType named type . | |
Protected Member Functions | |
KFilterBase * | filterBase () |
qint64 | readData (char *data, qint64 maxlen) override |
qint64 | writeData (const char *data, qint64 len) override |
A class for reading and writing compressed data onto a device (e.g.
file, but other usages are possible, like a buffer or a socket).
Use this class to read/write compressed files.
KCompressionDevice::KCompressionDevice | ( | QIODevice * | inputDevice, |
bool | autoDeleteInputDevice, | ||
CompressionType | type | ||
) |
Constructs a KCompressionDevice for a given CompressionType (e.g.
GZip, BZip2 etc.).
inputDevice | input device. |
autoDeleteInputDevice | if true, inputDevice will be deleted automatically |
type | the CompressionType to use. |
KCompressionDevice::KCompressionDevice | ( | const QString & | fileName, |
CompressionType | type | ||
) |
Constructs a KCompressionDevice for a given CompressionType (e.g.
GZip, BZip2 etc.).
fileName | the name of the file to filter. |
type | the CompressionType to use. |
KCompressionDevice::KCompressionDevice | ( | const QString & | fileName | ) |
Constructs a KCompressionDevice for a given fileName
.
fileName | the name of the file to filter. |
|
override |
Destructs the KCompressionDevice.
Calls close() if the filter device is still open.
|
override |
Close after reading or writing.
CompressionType KCompressionDevice::compressionType | ( | ) | const |
The compression actually used by this device.
If the support for the compression requested in the constructor is not available, then the device will use None.
|
static |
Returns the compression type for the given MIME type, if possible.
Otherwise returns None. This handles simple cases like application/gzip, but also application/x-compressed-tar, and inheritance.
QFileDevice::FileError KCompressionDevice::error | ( | ) | const |
Returns the error code from the last failing operation.
This is especially useful after calling close(), which unfortunately returns void (see https://bugreports.qt.io/browse/QTBUG-70033), to see if the flushing done by close was able to write all the data to disk.
|
static |
Call this to create the appropriate filter for the CompressionType named type
.
type | the type of the compression filter |
type
, or 0 if not found
|
override |
Open for reading or writing.
|
override |
That one can be quite slow, when going back.
Use with care.
void KCompressionDevice::setOrigFileName | ( | const QByteArray & | fileName | ) |
For writing gzip compressed files only: set the name of the original file, to be used in the gzip header.
fileName | the name of the original file |
void KCompressionDevice::setSkipHeaders | ( | ) |
Call this let this device skip the gzip headers when reading/writing.
This way KCompressionDevice (with gzip filter) can be used as a direct wrapper around zlib - this is used by KZip.