lz4.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. /*
  2. LZ4 - Fast LZ compression algorithm
  3. Header File
  4. Copyright (C) 2011-2012, Yann Collet.
  5. BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
  6. Redistribution and use in source and binary forms, with or without
  7. modification, are permitted provided that the following conditions are
  8. met:
  9. * Redistributions of source code must retain the above copyright
  10. notice, this list of conditions and the following disclaimer.
  11. * Redistributions in binary form must reproduce the above
  12. copyright notice, this list of conditions and the following disclaimer
  13. in the documentation and/or other materials provided with the
  14. distribution.
  15. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  16. "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  17. LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  18. A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  19. OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  20. SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  21. LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  22. DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  23. THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  24. (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  25. OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26. You can contact the author at :
  27. - LZ4 homepage : http://fastcompression.blogspot.com/p/lz4.html
  28. - LZ4 source repository : http://code.google.com/p/lz4/
  29. */
  30. #pragma once
  31. #if defined (__cplusplus)
  32. extern "C" {
  33. #endif
  34. //**************************************
  35. // Compiler Options
  36. //**************************************
  37. #if defined(_MSC_VER) && !defined(__cplusplus) // Visual Studio
  38. # define inline __inline // Visual is not C99, but supports some kind of inline
  39. #endif
  40. //****************************
  41. // Simple Functions
  42. //****************************
  43. int LZ4_compress (const char* source, char* dest, int isize);
  44. int LZ4_uncompress (const char* source, char* dest, int osize);
  45. /*
  46. LZ4_compress() :
  47. Compresses 'isize' bytes from 'source' into 'dest'.
  48. Destination buffer must be already allocated,
  49. and must be sized to handle worst cases situations (input data not compressible)
  50. Worst case size evaluation is provided by function LZ4_compressBound()
  51. isize : is the input size. Max supported value is ~1.9GB
  52. return : the number of bytes written in buffer dest
  53. LZ4_uncompress() :
  54. osize : is the output size, therefore the original size
  55. return : the number of bytes read in the source buffer
  56. If the source stream is malformed, the function will stop decoding and return a negative result, indicating the byte position of the faulty instruction
  57. This function never writes outside of provided buffers, and never modifies input buffer.
  58. note : destination buffer must be already allocated.
  59. its size must be a minimum of 'osize' bytes.
  60. */
  61. //****************************
  62. // Advanced Functions
  63. //****************************
  64. static inline int LZ4_compressBound(int isize) { return ((isize) + ((isize)/255) + 16); }
  65. #define LZ4_COMPRESSBOUND( isize) ((isize) + ((isize)/255) + 16)
  66. /*
  67. LZ4_compressBound() :
  68. Provides the maximum size that LZ4 may output in a "worst case" scenario (input data not compressible)
  69. primarily useful for memory allocation of output buffer.
  70. inline function is recommended for the general case,
  71. but macro is also provided when results need to be evaluated at compile time (such as table size allocation).
  72. isize : is the input size. Max supported value is ~1.9GB
  73. return : maximum output size in a "worst case" scenario
  74. note : this function is limited by "int" range (2^31-1)
  75. */
  76. int LZ4_compress_limitedOutput (const char* source, char* dest, int isize, int maxOutputSize);
  77. /*
  78. LZ4_compress_limitedOutput() :
  79. Compress 'isize' bytes from 'source' into an output buffer 'dest' of maximum size 'maxOutputSize'.
  80. If it cannot achieve it, compression will stop, and result of the function will be zero.
  81. This function never writes outside of provided output buffer.
  82. isize : is the input size. Max supported value is ~1.9GB
  83. maxOutputSize : is the size of the destination buffer (which must be already allocated)
  84. return : the number of bytes written in buffer 'dest'
  85. or 0 if the compression fails
  86. */
  87. int LZ4_uncompress_unknownOutputSize (const char* source, char* dest, int isize, int maxOutputSize);
  88. /*
  89. LZ4_uncompress_unknownOutputSize() :
  90. isize : is the input size, therefore the compressed size
  91. maxOutputSize : is the size of the destination buffer (which must be already allocated)
  92. return : the number of bytes decoded in the destination buffer (necessarily <= maxOutputSize)
  93. If the source stream is malformed, the function will stop decoding and return a negative result, indicating the byte position of the faulty instruction
  94. This function never writes beyond dest + maxOutputSize, and is therefore protected against malicious data packets
  95. note : Destination buffer must be already allocated.
  96. This version is slightly slower than LZ4_uncompress()
  97. */
  98. #if defined (__cplusplus)
  99. }
  100. #endif