Skip to content

Commit 351fd66

Browse files
metsmalauris71
andauthored
Un-export ChainedConsumer/Source (open-eid#98)
Signed-off-by: Raul Metsma <raul@metsma.ee> Co-authored-by: lauris71 <lauris@kaplinski.com>
1 parent cce504c commit 351fd66

File tree

3 files changed

+16
-49
lines changed

3 files changed

+16
-49
lines changed

cdoc/Io.h

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -209,45 +209,6 @@ struct CDOC_EXPORT MultiDataSource : public DataSource {
209209
result_t next(FileInfo& info) { return next(info.name, info.size); }
210210
};
211211

212-
struct CDOC_EXPORT ChainedConsumer : public DataConsumer {
213-
ChainedConsumer(DataConsumer *dst, bool take_ownership) : _dst(dst), _owned(take_ownership) {}
214-
~ChainedConsumer() {
215-
if (_owned) delete _dst;
216-
}
217-
result_t write(const uint8_t *src, size_t size) noexcept override {
218-
return _dst->write(src, size);
219-
}
220-
result_t close() noexcept override {
221-
if (_owned) return _dst->close();
222-
return OK;
223-
}
224-
bool isError() noexcept override {
225-
return _dst->isError();
226-
}
227-
protected:
228-
DataConsumer *_dst;
229-
bool _owned;
230-
};
231-
232-
struct CDOC_EXPORT ChainedSource : public DataSource {
233-
ChainedSource(DataSource *src, bool take_ownership) : _src(src), _owned(take_ownership) {}
234-
~ChainedSource() {
235-
if (_owned) delete _src;
236-
}
237-
result_t read(uint8_t *dst, size_t size) noexcept override {
238-
return _src->read(dst, size);
239-
}
240-
bool isError() noexcept override {
241-
return _src->isError();
242-
}
243-
bool isEof() noexcept override {
244-
return _src->isEof();
245-
}
246-
protected:
247-
DataSource *_src;
248-
bool _owned;
249-
};
250-
251212
struct CDOC_EXPORT IStreamSource : public DataSource {
252213
IStreamSource(std::istream *ifs, bool take_ownership = false) : _ifs(ifs), _owned(take_ownership) {}
253214
IStreamSource(const std::string& path);

cdoc/ZStream.h

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,20 @@
2828

2929
namespace libcdoc {
3030

31-
struct ZConsumer : public ChainedConsumer {
31+
struct ZConsumer : public DataConsumer {
3232
static constexpr uint64_t CHUNK = 16LL * 1024LL;
33+
DataConsumer *_dst;
34+
bool _owned;
3335
z_stream _s {};
3436
bool _fail = false;
3537
int flush = Z_NO_FLUSH;
36-
ZConsumer(DataConsumer *dst, bool take_ownership = false) : ChainedConsumer(dst, take_ownership) {
38+
ZConsumer(DataConsumer *dst, bool take_ownership = false)
39+
: _dst(dst), _owned(take_ownership) {
3740
if (deflateInit(&_s, Z_DEFAULT_COMPRESSION) != Z_OK) _fail = true;
3841
}
3942
~ZConsumer() {
4043
if (!_fail) deflateEnd(&_s);
44+
if (_owned) delete _dst;
4145
}
4246

4347
libcdoc::result_t write(const uint8_t *src, size_t size) noexcept final {
@@ -64,30 +68,34 @@ struct ZConsumer : public ChainedConsumer {
6468
}
6569

6670
virtual bool isError() noexcept final {
67-
return _fail || ChainedConsumer::isError();
71+
return _fail || _dst->isError();
6872
};
6973

7074
libcdoc::result_t close() noexcept final {
7175
flush = Z_FINISH;
7276
write (nullptr, 0);
7377
deflateEnd(&_s);
74-
return ChainedConsumer::close();
78+
if (_owned) return _dst->close();
7579
}
7680
};
7781

78-
struct ZSource : public ChainedSource {
82+
struct ZSource : public DataSource {
7983
static constexpr uint64_t CHUNK = 16LL * 1024LL;
84+
DataSource *_src;
85+
bool _owned;
8086
z_stream _s {};
8187
int64_t _error = OK;
8288
std::vector<uint8_t> buf;
8389
int flush = Z_NO_FLUSH;
84-
ZSource(DataSource *src, bool take_ownership = false) : ChainedSource(src, take_ownership) {
90+
ZSource(DataSource *src, bool take_ownership = false)
91+
: _src(src), _owned(take_ownership) {
8592
if (inflateInit2(&_s, MAX_WBITS) != Z_OK) {
8693
_error = ZLIB_ERROR;
8794
}
8895
}
8996
~ZSource() {
9097
if (!_error) inflateEnd(&_s);
98+
if (_owned) delete _src;
9199
}
92100

93101
libcdoc::result_t read(uint8_t *dst, size_t size) noexcept final try {
@@ -125,11 +133,11 @@ struct ZSource : public ChainedSource {
125133
}
126134

127135
virtual bool isError() noexcept final {
128-
return (_error != OK) || ChainedSource::isError();
136+
return (_error != OK) || _src->isError();
129137
};
130138

131139
virtual bool isEof() noexcept final {
132-
return (_s.avail_in == 0) && ChainedSource::isEof();
140+
return (_s.avail_in == 0) && _src->isEof();
133141
};
134142
};
135143

libcdoc.i

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,6 @@
4444

4545
%ignore libcdoc::MultiDataSource;
4646
%ignore libcdoc::MultiDataConsumer;
47-
%ignore libcdoc::ChainedConsumer;
48-
%ignore libcdoc::ChainedSource;
4947
%ignore libcdoc::IStreamSource;
5048
%ignore libcdoc::OStreamConsumer;
5149
%ignore libcdoc::VectorConsumer;

0 commit comments

Comments
 (0)