KArchive

knonefilter.cpp
1 /* This file is part of the KDE libraries
2  SPDX-FileCopyrightText: 2011 Mario Bensi <[email protected]>
3 
4  Based on kbzip2filter:
5  SPDX-FileCopyrightText: 2000, 2009 David Faure <[email protected]>
6 
7  SPDX-License-Identifier: LGPL-2.0-or-later
8 */
9 
10 #include "knonefilter.h"
11 
12 #include <QFile>
13 
14 class Q_DECL_HIDDEN KNoneFilter::Private
15 {
16 public:
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 
33 KNoneFilter::KNoneFilter()
34  : d(new Private)
35 {
36 }
37 
38 KNoneFilter::~KNoneFilter()
39 {
40  delete d;
41 }
42 
43 bool KNoneFilter::init(int mode)
44 {
45  d->mode = mode;
46  return true;
47 }
48 
49 int KNoneFilter::mode() const
50 {
51  return d->mode;
52 }
53 
55 {
56  return true;
57 }
58 
60 {
61 }
62 
64 {
65  return true;
66 }
67 
68 bool KNoneFilter::writeHeader(const QByteArray & /*fileName*/)
69 {
70  return true;
71 }
72 
73 void KNoneFilter::setOutBuffer(char *data, uint maxlen)
74 {
75  d->avail_out = maxlen;
76  d->next_out = data;
77 }
78 
79 void 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 
113 KNoneFilter::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 }
int mode() const override
Definition: knonefilter.cpp:49
int outBufferAvailable() const override
Definition: knonefilter.cpp:90
void setOutBuffer(char *data, uint maxlen) override
Definition: knonefilter.cpp:73
Result uncompress() override
Definition: knonefilter.cpp:95
bool terminate() override
Definition: knonefilter.cpp:54
void setInBuffer(const char *data, uint size) override
Definition: knonefilter.cpp:79
bool init(int mode) override
Definition: knonefilter.cpp:43
int inBufferAvailable() const override
Definition: knonefilter.cpp:85
bool readHeader() override
Definition: knonefilter.cpp:63
Internal class used by KCompressionDevice.
Definition: knonefilter.h:22
void reset() override
Definition: knonefilter.cpp:59
bool writeHeader(const QByteArray &fileName) override
Definition: knonefilter.cpp:68
Result compress(bool finish) override
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Tue Aug 16 2022 04:03:12 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.