1 | /* |
2 | FastLZ - Byte-aligned LZ77 compression library |
3 | Copyright (C) 2005-2020 Ariya Hidayat <ariya.hidayat@gmail.com> |
4 | |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy |
6 | of this software and associated documentation files (the "Software"), to deal |
7 | in the Software without restriction, including without limitation the rights |
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
9 | copies of the Software, and to permit persons to whom the Software is |
10 | furnished to do so, subject to the following conditions: |
11 | |
12 | The above copyright notice and this permission notice shall be included in |
13 | all copies or substantial portions of the Software. |
14 | |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
21 | THE SOFTWARE. |
22 | */ |
23 | |
24 | #ifndef FASTLZ_H |
25 | #define FASTLZ_H |
26 | |
27 | #define FASTLZ_VERSION 0x000500 |
28 | |
29 | #define FASTLZ_VERSION_MAJOR 0 |
30 | #define FASTLZ_VERSION_MINOR 5 |
31 | #define FASTLZ_VERSION_REVISION 0 |
32 | |
33 | #define FASTLZ_VERSION_STRING "0.5.0" |
34 | |
35 | #if defined(__cplusplus) |
36 | extern "C" { |
37 | #endif |
38 | |
39 | /** |
40 | Compress a block of data in the input buffer and returns the size of |
41 | compressed block. The size of input buffer is specified by length. The |
42 | minimum input buffer size is 16. |
43 | |
44 | The output buffer must be at least 5% larger than the input buffer |
45 | and can not be smaller than 66 bytes. |
46 | |
47 | If the input is not compressible, the return value might be larger than |
48 | length (input buffer size). |
49 | |
50 | The input buffer and the output buffer can not overlap. |
51 | |
52 | Compression level can be specified in parameter level. At the moment, |
53 | only level 1 and level 2 are supported. |
54 | Level 1 is the fastest compression and generally useful for short data. |
55 | Level 2 is slightly slower but it gives better compression ratio. |
56 | |
57 | Note that the compressed data, regardless of the level, can always be |
58 | decompressed using the function fastlz_decompress below. |
59 | */ |
60 | |
61 | int fastlz_compress_level(int level, const void* input, int length, |
62 | void* output); |
63 | |
64 | /** |
65 | Decompress a block of compressed data and returns the size of the |
66 | decompressed block. If error occurs, e.g. the compressed data is |
67 | corrupted or the output buffer is not large enough, then 0 (zero) |
68 | will be returned instead. |
69 | |
70 | The input buffer and the output buffer can not overlap. |
71 | |
72 | Decompression is memory safe and guaranteed not to write the output buffer |
73 | more than what is specified in maxout. |
74 | |
75 | Note that the decompression will always work, regardless of the |
76 | compression level specified in fastlz_compress_level above (when |
77 | producing the compressed block). |
78 | */ |
79 | |
80 | int fastlz_decompress(const void* input, int length, void* output, int maxout); |
81 | |
82 | /** |
83 | DEPRECATED. |
84 | |
85 | This is similar to fastlz_compress_level above, but with the level |
86 | automatically chosen. |
87 | |
88 | This function is deprecated and it will be completely removed in some future |
89 | version. |
90 | */ |
91 | |
92 | int fastlz_compress(const void* input, int length, void* output); |
93 | |
94 | #if defined(__cplusplus) |
95 | } |
96 | #endif |
97 | |
98 | #endif /* FASTLZ_H */ |
99 | |