1/* This file is part of the KDE libraries
2 SPDX-FileCopyrightText: 2000 David Faure <faure@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6
7#ifndef __kfilterbase__h
8#define __kfilterbase__h
9
10#include <karchive_export.h>
11
12#include <QObject>
13#include <QString>
14class KFilterBasePrivate;
15
16class QIODevice;
17
18/**
19 * @class KFilterBase kfilterbase.h KFilterBase
20 *
21 * This is the base class for compression filters
22 * such as gzip and bzip2. It's pretty much internal.
23 * Don't use directly, use KCompressionDevice instead.
24 * @internal
25 */
26class KARCHIVE_EXPORT KFilterBase
27{
28public:
29 KFilterBase();
30 virtual ~KFilterBase();
31
32 /**
33 * Sets the device on which the filter will work
34 * @param dev the device on which the filter will work
35 * @param autodelete if true, @p dev is deleted when the filter is deleted
36 */
37 void setDevice(QIODevice *dev, bool autodelete = false);
38 // Note that this isn't in the constructor, because of KLibFactory::create,
39 // but it should be called before using the filterbase !
40
41 /**
42 * Returns the device on which the filter will work.
43 * @returns the device on which the filter will work
44 */
45 QIODevice *device();
46 /** \internal */
47 virtual bool init(int mode) = 0;
48 /** \internal */
49 virtual int mode() const = 0;
50 /** \internal */
51 virtual bool terminate();
52 /** \internal */
53 virtual void reset();
54 /** \internal */
55 virtual bool readHeader() = 0;
56 /** \internal */
57 virtual bool writeHeader(const QByteArray &filename) = 0;
58 /** \internal */
59 virtual void setOutBuffer(char *data, uint maxlen) = 0;
60 /** \internal */
61 virtual void setInBuffer(const char *data, uint size) = 0;
62 /** \internal */
63 virtual bool inBufferEmpty() const;
64 /** \internal */
65 virtual int inBufferAvailable() const = 0;
66 /** \internal */
67 virtual bool outBufferFull() const;
68 /** \internal */
69 virtual int outBufferAvailable() const = 0;
70
71 /** \internal */
72 enum Result {
73 Ok,
74 End,
75 Error,
76 };
77 /** \internal */
78 virtual Result uncompress() = 0;
79 /** \internal */
80 virtual Result compress(bool finish) = 0;
81
82 /**
83 * \internal
84 * \since 4.3
85 */
86 enum FilterFlags {
87 NoHeaders = 0,
88 WithHeaders = 1,
89 ZlibHeaders = 2, // only use for gzip compression
90 };
91 /**
92 * \internal
93 * \since 4.3
94 */
95 void setFilterFlags(FilterFlags flags);
96 FilterFlags filterFlags() const;
97
98protected:
99 /** Virtual hook, used to add new "virtual" functions while maintaining
100 binary compatibility. Unused in this class.
101 */
102 virtual void virtual_hook(int id, void *data);
103
104private:
105 Q_DISABLE_COPY(KFilterBase)
106 KFilterBasePrivate *const d;
107};
108
109#endif
110

source code of karchive/src/kfilterbase.h