KArchive

knonefilter.cpp
1/* This file is part of the KDE libraries
2 SPDX-FileCopyrightText: 2011 Mario Bensi <mbensi@ipsquad.net>
3
4 Based on kbzip2filter:
5 SPDX-FileCopyrightText: 2000, 2009 David Faure <faure@kde.org>
6
7 SPDX-License-Identifier: LGPL-2.0-or-later
8*/
9
10#include "knonefilter.h"
11
12#include <QFile>
13
14class Q_DECL_HIDDEN KNoneFilter::Private
15{
16public:
17 Private()
18 : mode(0)
19 , avail_out(0)
20 , avail_in(0)
21 , next_in(nullptr)
22 , next_out(nullptr)
23 {
24 }
25
26 int mode;
27 int avail_out;
28 int avail_in;
29 const char *next_in;
30 char *next_out;
31};
32
33KNoneFilter::KNoneFilter()
34 : d(new Private)
35{
36}
37
38KNoneFilter::~KNoneFilter()
39{
40 delete d;
41}
42
43bool KNoneFilter::init(int mode)
44{
45 d->mode = mode;
46 return true;
47}
48
50{
51 return d->mode;
52}
53
55{
56 return true;
57}
58
60{
61}
62
64{
65 return true;
66}
67
68bool KNoneFilter::writeHeader(const QByteArray & /*fileName*/)
69{
70 return true;
71}
72
73void KNoneFilter::setOutBuffer(char *data, uint maxlen)
74{
75 d->avail_out = maxlen;
76 d->next_out = data;
77}
78
79void KNoneFilter::setInBuffer(const char *data, uint size)
80{
81 d->next_in = data;
82 d->avail_in = size;
83}
84
86{
87 return d->avail_in;
88}
89
91{
92 return d->avail_out;
93}
94
96{
97#ifndef NDEBUG
98 if (d->mode != QIODevice::ReadOnly) {
99 return KFilterBase::Error;
100 }
101#endif
102 return copyData();
103}
104
106{
107 Q_ASSERT(d->mode == QIODevice::WriteOnly);
108 Q_UNUSED(finish);
109
110 return copyData();
111}
112
113KNoneFilter::Result KNoneFilter::copyData()
114{
115 Q_ASSERT(d->avail_out > 0);
116 if (d->avail_in > 0) {
117 const int n = qMin(d->avail_in, d->avail_out);
118 memcpy(d->next_out, d->next_in, n);
119 d->avail_out -= n;
120 d->next_in += n;
121 d->next_out += n;
122 d->avail_in -= n;
123 return KFilterBase::Ok;
124 } else {
125 return KFilterBase::End;
126 }
127}
Internal class used by KCompressionDevice.
Definition knonefilter.h:23
void setInBuffer(const char *data, uint size) override
Result compress(bool finish) override
bool writeHeader(const QByteArray &fileName) override
int outBufferAvailable() const override
bool readHeader() override
bool terminate() override
Result uncompress() override
int mode() const override
void setOutBuffer(char *data, uint maxlen) override
void reset() override
int inBufferAvailable() const override
bool init(int mode) override
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Jun 14 2024 11:47:54 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.