KArchive 5.109.0
Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | List of all members
KCompressionDevice

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 KFilterBasefilterForCompressionType (CompressionType type)
 Call this to create the appropriate filter for the CompressionType named type.
 

Protected Member Functions

KFilterBasefilterBase ()
 
qint64 readData (char *data, qint64 maxlen) override
 
qint64 writeData (const char *data, qint64 len) override
 

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 Enumeration Documentation

◆ CompressionType

Enumerator
Zstd 
Since
5.82

Constructor & Destructor Documentation

◆ KCompressionDevice() [1/3]

KCompressionDevice::KCompressionDevice ( QIODevice *  inputDevice,
bool  autoDeleteInputDevice,
CompressionType  type 
)

Constructs a KCompressionDevice for a given CompressionType (e.g.

GZip, BZip2 etc.).

Parameters
inputDeviceinput device.
autoDeleteInputDeviceif true, inputDevice will be deleted automatically
typethe CompressionType to use.

◆ KCompressionDevice() [2/3]

KCompressionDevice::KCompressionDevice ( const QString &  fileName,
CompressionType  type 
)

Constructs a KCompressionDevice for a given CompressionType (e.g.

GZip, BZip2 etc.).

Parameters
fileNamethe name of the file to filter.
typethe CompressionType to use.

◆ KCompressionDevice() [3/3]

KCompressionDevice::KCompressionDevice ( const QString &  fileName)

Constructs a KCompressionDevice for a given fileName.

Parameters
fileNamethe name of the file to filter.
Since
5.85

◆ ~KCompressionDevice()

KCompressionDevice::~KCompressionDevice ( )
override

Destructs the KCompressionDevice.

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

Member Function Documentation

◆ close()

void KCompressionDevice::close ( )
override

Close after reading or writing.

◆ compressionType()

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.

◆ compressionTypeForMimeType()

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

Since
5.85

◆ error()

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.

◆ filterForCompressionType()

static KFilterBase * KCompressionDevice::filterForCompressionType ( CompressionType  type)
static

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

Parameters
typethe type of the compression filter
Returns
the filter for the type, or 0 if not found

◆ open()

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

Open for reading or writing.

◆ seek()

bool KCompressionDevice::seek ( qint64  )
override

That one can be quite slow, when going back.

Use with care.

◆ setOrigFileName()

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.

Parameters
fileNamethe name of the original file

◆ setSkipHeaders()

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.