|
| 1 | +#ifndef LZF_H |
| 2 | +#define LZF_H |
| 3 | + |
| 4 | +/* API version (major * 256 + minor) |
| 5 | + * major API version gets bumped on incompatible changes. |
| 6 | + * minor API version gets bumped on compatible changes. |
| 7 | + * 1.5 => 1.6: add LZF_MAX_COMPRESSED_SIZE |
| 8 | + */ |
| 9 | +#define LZF_VERSION 0x0106 |
| 10 | + |
| 11 | +/* |
| 12 | + * Compress in_len bytes stored at the memory block starting at |
| 13 | + * in_data and write the result to out_data, up to a maximum length |
| 14 | + * of out_len bytes. |
| 15 | + * |
| 16 | + * If the output buffer is not large enough or any error occurs return 0, |
| 17 | + * otherwise return the number of bytes used, which might be considerably |
| 18 | + * more than in_len (but less than 1 + 104% of the original size), so it |
| 19 | + * makes sense to always use out_len == in_len - 1), to ensure _some_ |
| 20 | + * compression, and store the data uncompressed otherwise (with a flag, of |
| 21 | + * course. |
| 22 | + * |
| 23 | + * lzf_compress might use different algorithms on different systems and |
| 24 | + * even different runs, thus might result in different compressed strings |
| 25 | + * depending on the phase of the moon or similar factors. However, all |
| 26 | + * these strings are architecture-independent and will result in the |
| 27 | + * original data when decompressed using lzf_decompress. |
| 28 | + * |
| 29 | + * The buffers must not be overlapping. |
| 30 | + * |
| 31 | + * If the option LZF_STATE_ARG is enabled, an extra argument must be |
| 32 | + * supplied which is not reflected in this header file. Refer to lzfP.h |
| 33 | + * and lzf_c.c. |
| 34 | + * |
| 35 | + */ |
| 36 | +unsigned int lzf_compress (const void *const in_data, unsigned int in_len, void *out_data, unsigned int out_len); |
| 37 | + |
| 38 | +/* |
| 39 | + * The maximum out_len that needs to be allocated to make sure |
| 40 | + * any input data can be compressed without overflowing the output |
| 41 | + * buffer, i.e. maximum out_len = LZF_MAX_COMPRESSED_SIZE (in_len). |
| 42 | + * This is useful if you don't want to bother with the case of |
| 43 | + * incompressible data and just want to provide a buffer that is |
| 44 | + * guaranteeed to be big enough. |
| 45 | + * This macro can be used at preprocessing time. |
| 46 | + */ |
| 47 | +#define LZF_MAX_COMPRESSED_SIZE(n) ((((n) * 33) >> 5 ) + 1) |
| 48 | + |
| 49 | +/* |
| 50 | + * Decompress data compressed with some version of the lzf_compress |
| 51 | + * function and stored at location in_data and length in_len. The result |
| 52 | + * will be stored at out_data up to a maximum of out_len characters. |
| 53 | + * |
| 54 | + * If the output buffer is not large enough to hold the decompressed |
| 55 | + * data, a 0 is returned and errno is set to E2BIG. Otherwise the number |
| 56 | + * of decompressed bytes (i.e. the original length of the data) is |
| 57 | + * returned. |
| 58 | + * |
| 59 | + * If an error in the compressed data is detected, a zero is returned and |
| 60 | + * errno is set to EINVAL. |
| 61 | + * |
| 62 | + * This function is very fast, about as fast as a copying loop. |
| 63 | + */ |
| 64 | +unsigned int lzf_decompress (const void *const in_data, unsigned int in_len, void *out_data, unsigned int out_len); |
| 65 | + |
| 66 | +#endif |
0 commit comments