xref: /haiku/headers/private/support/ZstdCompressionAlgorithm.h (revision 4c8e85b316c35a9161f5a1c50ad70bc91c83a76f)
1 /*
2  * Copyright 2017, Jérôme Duval.
3  * Copyright 2014, Ingo Weinhold, ingo_weinhold@gmx.de.
4  * Distributed under the terms of the MIT License.
5  */
6 #ifndef _ZSTD_COMPRESSION_ALGORITHM_H_
7 #define _ZSTD_COMPRESSION_ALGORITHM_H_
8 
9 
10 #include <CompressionAlgorithm.h>
11 
12 
13 // compression level
14 enum {
15 	B_ZSTD_COMPRESSION_NONE		= 0,
16 	B_ZSTD_COMPRESSION_FASTEST	= 1,
17 	B_ZSTD_COMPRESSION_BEST		= 22,
18 	B_ZSTD_COMPRESSION_DEFAULT	= 4,
19 };
20 
21 
22 class BZstdCompressionParameters : public BCompressionParameters {
23 public:
24 								BZstdCompressionParameters(
25 									int compressionLevel
26 										= B_ZSTD_COMPRESSION_DEFAULT);
27 	virtual						~BZstdCompressionParameters();
28 
29 			int32				CompressionLevel() const;
30 			void				SetCompressionLevel(int32 level);
31 
32 			size_t				BufferSize() const;
33 			void				SetBufferSize(size_t size);
34 
35 private:
36 			int32				fCompressionLevel;
37 			size_t				fBufferSize;
38 };
39 
40 
41 class BZstdDecompressionParameters : public BDecompressionParameters {
42 public:
43 								BZstdDecompressionParameters();
44 	virtual						~BZstdDecompressionParameters();
45 
46 			size_t				BufferSize() const;
47 			void				SetBufferSize(size_t size);
48 
49 private:
50 			size_t				fBufferSize;
51 };
52 
53 
54 class BZstdCompressionAlgorithm : public BCompressionAlgorithm {
55 public:
56 								BZstdCompressionAlgorithm();
57 	virtual						~BZstdCompressionAlgorithm();
58 
59 	virtual	status_t			CreateCompressingInputStream(BDataIO* input,
60 									const BCompressionParameters* parameters,
61 									BDataIO*& _stream);
62 	virtual	status_t			CreateCompressingOutputStream(BDataIO* output,
63 									const BCompressionParameters* parameters,
64 									BDataIO*& _stream);
65 	virtual	status_t			CreateDecompressingInputStream(BDataIO* input,
66 									const BDecompressionParameters* parameters,
67 									BDataIO*& _stream);
68 	virtual	status_t			CreateDecompressingOutputStream(BDataIO* output,
69 									const BDecompressionParameters* parameters,
70 									BDataIO*& _stream);
71 
72 	virtual	status_t			CompressBuffer(const void* input,
73 									size_t inputSize, void* output,
74 									size_t outputSize, size_t& _compressedSize,
75 									const BCompressionParameters* parameters
76 										= NULL);
77 	virtual	status_t			DecompressBuffer(const void* input,
78 									size_t inputSize, void* output,
79 									size_t outputSize,
80 									size_t& _uncompressedSize,
81 									const BDecompressionParameters* parameters
82 										= NULL);
83 
84 private:
85 			struct CompressionStrategy;
86 			struct DecompressionStrategy;
87 
88 			template<typename BaseClass, typename Strategy, typename StreamType> struct Stream;
89 			template<typename BaseClass, typename Strategy, typename StreamType>
90 				friend struct Stream;
91 
92 private:
93 	static	status_t			_TranslateZstdError(size_t error);
94 };
95 
96 
97 #endif	// _ZSTD_COMPRESSION_ALGORITHM_H_
98