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
49int KNoneFilter::mode() const
50{
51 return d->mode;
52}
53
54bool KNoneFilter::terminate()
55{
56 return true;
57}
58
59void KNoneFilter::reset()
60{
61}
62
63bool KNoneFilter::readHeader()
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
85int KNoneFilter::inBufferAvailable() const
86{
87 return d->avail_in;
88}
89
90int KNoneFilter::outBufferAvailable() const
91{
92 return d->avail_out;
93}
94
95KNoneFilter::Result KNoneFilter::uncompress()
96{
97#ifndef NDEBUG
98 if (d->mode != QIODevice::ReadOnly) {
99 return KFilterBase::Error;
100 }
101#endif
102 return copyData();
103}
104
105KNoneFilter::Result KNoneFilter::compress(bool finish)
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(a: d->avail_in, b: d->avail_out);
118 memcpy(dest: d->next_out, src: d->next_in, n: 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}
128

source code of karchive/src/knonefilter.cpp