2 * Copyright 2014, Ingo Weinhold, ingo_weinhold@gmx.de.
3 * Distributed under the terms of the MIT License.
5 #ifndef _COMPRESSION_ALGORITHM_H_
6 #define _COMPRESSION_ALGORITHM_H_
12 class BCompressionParameters
{
14 BCompressionParameters();
15 virtual ~BCompressionParameters();
19 class BDecompressionParameters
{
21 BDecompressionParameters();
22 virtual ~BDecompressionParameters();
26 class BCompressionAlgorithm
{
28 BCompressionAlgorithm();
29 virtual ~BCompressionAlgorithm();
31 virtual status_t
CreateCompressingInputStream(BDataIO
* input
,
32 const BCompressionParameters
* parameters
,
34 virtual status_t
CreateCompressingOutputStream(BDataIO
* output
,
35 const BCompressionParameters
* parameters
,
37 virtual status_t
CreateDecompressingInputStream(BDataIO
* input
,
38 const BDecompressionParameters
* parameters
,
40 virtual status_t
CreateDecompressingOutputStream(BDataIO
* output
,
41 const BDecompressionParameters
* parameters
,
44 virtual status_t
CompressBuffer(const void* input
,
45 size_t inputSize
, void* output
,
46 size_t outputSize
, size_t& _compressedSize
,
47 const BCompressionParameters
* parameters
49 virtual status_t
DecompressBuffer(const void* input
,
50 size_t inputSize
, void* output
,
52 size_t& _uncompressedSize
,
53 const BDecompressionParameters
* parameters
57 class BAbstractStream
;
58 class BAbstractInputStream
;
59 class BAbstractOutputStream
;
63 class BCompressionAlgorithm::BAbstractStream
: public BDataIO
{
66 virtual ~BAbstractStream();
68 status_t
Init(size_t bufferSize
);
71 virtual status_t
ProcessData(const void* input
, size_t inputSize
,
72 void* output
, size_t outputSize
,
73 size_t& bytesConsumed
,
74 size_t& bytesProduced
) = 0;
75 // must consume or produce at least 1 byte
77 virtual status_t
FlushPendingData(void* output
,
79 size_t& bytesProduced
) = 0;
83 size_t fBufferCapacity
;
89 class BCompressionAlgorithm::BAbstractInputStream
: public BAbstractStream
{
91 BAbstractInputStream(BDataIO
* input
);
92 virtual ~BAbstractInputStream();
94 virtual ssize_t
Read(void* buffer
, size_t size
);
99 bool fNoMorePendingData
;
103 class BCompressionAlgorithm::BAbstractOutputStream
: public BAbstractStream
{
105 BAbstractOutputStream(BDataIO
* output
);
106 virtual ~BAbstractOutputStream();
108 virtual ssize_t
Write(const void* buffer
, size_t size
);
110 virtual status_t
Flush();
113 ssize_t
_Write(const void* buffer
, size_t size
,
121 #endif // _COMPRESSION_ALGORITHM_H_