Pages
API Documentation
On this page

KCompressionDevice Class

QIODevice for reading compressed data. More...

  • Header: #include <KCompressionDevice>
  • CMake: find_package(KF6 REQUIRED COMPONENTS Archive)
    target_link_libraries(mytarget PRIVATE KF6::Archive)
  • Inherits: QIODevice

List of all members, including inherited members

Public Types

Public Functions

Static Public Members

Detailed Description

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.

Member Type Documentation

enum KCompressionDevice::CompressionType

Constant
KCompressionDevice::GZip 0
KCompressionDevice::BZip2 1
KCompressionDevice::Xz 2
KCompressionDevice::None 3
KCompressionDevice::Zstd (since Qt 5.82) 4
KCompressionDevice::Lz (since Qt 6.15) 5

Member Function Documentation

[explicit] KCompressionDevice::KCompressionDevice(const QString &fileName)

Constructs a KCompressionDevice for a given fileName.

fileName the name of the file to filter.

KCompressionDevice::KCompressionDevice(const QString &fileName, KCompressionDevice::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(QIODevice *inputDevice, bool autoDeleteInputDevice, KCompressionDevice::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.

[since 6.16] KCompressionDevice::KCompressionDevice(std::unique_ptr<QIODevice> inputDevice, KCompressionDevice::CompressionType type, std::optional<qint64> size = {})

Constructs a KCompressionDevice for a given CompressionType (e.g. GZip, BZip2 etc.).

inputDevice input device.

type the CompressionType to use.

size the size we know the inputDevice with CompressionType type has. If we know it.

This function was introduced in Qt 6.16.

[override virtual noexcept] KCompressionDevice::~KCompressionDevice()

Destructs the KCompressionDevice.

Calls close() if the filter device is still open.

KCompressionDevice::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] KCompressionDevice::CompressionType KCompressionDevice::compressionTypeForMimeType(const QString &mimetype)

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] KFilterBase *KCompressionDevice::filterForCompressionType(KCompressionDevice::CompressionType type)

Call this to create the appropriate filter for the CompressionType named type.

type the type of the compression filter

Returns the filter for the type, or 0 if not found

[override virtual] bool KCompressionDevice::seek(qint64)

Reimplements: QIODevice::seek(qint64 pos).

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.

We use cookies to personalize content and to analyze our traffic. Please decide if you are willing to accept cookies from our website.