fastlz.h 3.3 KB

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