KArchive 5.109.0
kcompressiondevice.h
1/* This file is part of the KDE libraries
2 SPDX-FileCopyrightText: 2000 David Faure <faure@kde.org>
3 SPDX-FileCopyrightText: 2011 Mario Bensi <mbensi@ipsquad.net>
4
5 SPDX-License-Identifier: LGPL-2.0-or-later
6*/
7#ifndef __kcompressiondevice_h
8#define __kcompressiondevice_h
9
10#include <karchive_export.h>
11
12#include <QFileDevice>
13#include <QIODevice>
14#include <QMetaType>
15#include <QString>
16
17class KCompressionDevicePrivate;
18
19class KFilterBase;
20
30class KARCHIVE_EXPORT KCompressionDevice : public QIODevice // KF6 TODO: consider inheriting from QFileDevice, so apps can use error() generically ?
31{
32 Q_OBJECT
33public:
35 GZip,
36 BZip2,
37 Xz,
38 None,
40 };
41
48 KCompressionDevice(QIODevice *inputDevice, bool autoDeleteInputDevice, CompressionType type);
49
55 KCompressionDevice(const QString &fileName, CompressionType type);
56
62 KCompressionDevice(const QString &fileName);
63
69
76
80 bool open(QIODevice::OpenMode mode) override;
81
85 void close() override;
86
92 void setOrigFileName(const QByteArray &fileName);
93
100
104 bool seek(qint64) override;
105
106 bool atEnd() const override;
107
115
121 static CompressionType compressionTypeForMimeType(const QString &mimetype);
122
129 QFileDevice::FileError error() const;
130
131protected:
132 friend class K7Zip;
133
134 qint64 readData(char *data, qint64 maxlen) override;
135 qint64 writeData(const char *data, qint64 len) override;
136
137 KFilterBase *filterBase();
138
139private:
140 friend KCompressionDevicePrivate;
141 KCompressionDevicePrivate *const d;
142};
143
144Q_DECLARE_METATYPE(KCompressionDevice::CompressionType)
145
146#endif
A class for reading / writing p7zip archives.
Definition k7zip.h:19
A class for reading and writing compressed data onto a device (e.g.
Definition kcompressiondevice.h:31
KCompressionDevice(const QString &fileName, CompressionType type)
Constructs a KCompressionDevice for a given CompressionType (e.g.
void setOrigFileName(const QByteArray &fileName)
For writing gzip compressed files only: set the name of the original file, to be used in the gzip hea...
KCompressionDevice(QIODevice *inputDevice, bool autoDeleteInputDevice, CompressionType type)
Constructs a KCompressionDevice for a given CompressionType (e.g.
CompressionType compressionType() const
The compression actually used by this device.
QFileDevice::FileError error() const
Returns the error code from the last failing operation.
bool seek(qint64) override
That one can be quite slow, when going back.
CompressionType
Definition kcompressiondevice.h:34
@ Zstd
Definition kcompressiondevice.h:39
void close() override
Close after reading or writing.
~KCompressionDevice() override
Destructs the KCompressionDevice.
void setSkipHeaders()
Call this let this device skip the gzip headers when reading/writing.
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.
KCompressionDevice(const QString &fileName)
Constructs a KCompressionDevice for a given fileName.
bool open(QIODevice::OpenMode mode) override
Open for reading or writing.
This is the base class for compression filters such as gzip and bzip2.
Definition kfilterbase.h:27