zstd_v07.h 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. #include <contrib/libs/zstd06/renames.h>
  2. /*
  3. zstd - standard compression library
  4. Header File
  5. Copyright (C) 2014-2016, Yann Collet.
  6. BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
  7. Redistribution and use in source and binary forms, with or without
  8. modification, are permitted provided that the following conditions are
  9. met:
  10. * Redistributions of source code must retain the above copyright
  11. notice, this list of conditions and the following disclaimer.
  12. * Redistributions in binary form must reproduce the above
  13. copyright notice, this list of conditions and the following disclaimer
  14. in the documentation and/or other materials provided with the
  15. distribution.
  16. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  17. "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  18. LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  19. A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  20. OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  21. SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  22. LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  23. DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  24. THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  25. (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  26. OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  27. You can contact the author at :
  28. - zstd source repository : https://github.com/Cyan4973/zstd
  29. */
  30. #ifndef ZSTDv07_H_235446
  31. #define ZSTDv07_H_235446
  32. #if defined (__cplusplus)
  33. extern "C" {
  34. #endif
  35. /*====== Dependency ======*/
  36. #include <stddef.h> /* size_t */
  37. /*====== Export for Windows ======*/
  38. /*!
  39. * ZSTDv07_DLL_EXPORT :
  40. * Enable exporting of functions when building a Windows DLL
  41. */
  42. #if defined(_WIN32) && defined(ZSTDv07_DLL_EXPORT) && (ZSTDv07_DLL_EXPORT==1)
  43. # define ZSTDLIB_API __declspec(dllexport)
  44. #else
  45. # define ZSTDLIB_API
  46. #endif
  47. /* *************************************
  48. * Simple API
  49. ***************************************/
  50. /*! ZSTDv07_getDecompressedSize() :
  51. * @return : decompressed size if known, 0 otherwise.
  52. note 1 : if `0`, follow up with ZSTDv07_getFrameParams() to know precise failure cause.
  53. note 2 : decompressed size could be wrong or intentionally modified !
  54. always ensure results fit within application's authorized limits */
  55. unsigned long long ZSTDv07_getDecompressedSize(const void* src, size_t srcSize);
  56. /*! ZSTDv07_decompress() :
  57. `compressedSize` : must be _exact_ size of compressed input, otherwise decompression will fail.
  58. `dstCapacity` must be equal or larger than originalSize.
  59. @return : the number of bytes decompressed into `dst` (<= `dstCapacity`),
  60. or an errorCode if it fails (which can be tested using ZSTDv07_isError()) */
  61. ZSTDLIB_API size_t ZSTDv07_decompress( void* dst, size_t dstCapacity,
  62. const void* src, size_t compressedSize);
  63. /*====== Helper functions ======*/
  64. ZSTDLIB_API unsigned ZSTDv07_isError(size_t code); /*!< tells if a `size_t` function result is an error code */
  65. ZSTDLIB_API const char* ZSTDv07_getErrorName(size_t code); /*!< provides readable string from an error code */
  66. /*-*************************************
  67. * Explicit memory management
  68. ***************************************/
  69. /** Decompression context */
  70. typedef struct ZSTDv07_DCtx_s ZSTDv07_DCtx;
  71. ZSTDLIB_API ZSTDv07_DCtx* ZSTDv07_createDCtx(void);
  72. ZSTDLIB_API size_t ZSTDv07_freeDCtx(ZSTDv07_DCtx* dctx); /*!< @return : errorCode */
  73. /** ZSTDv07_decompressDCtx() :
  74. * Same as ZSTDv07_decompress(), requires an allocated ZSTDv07_DCtx (see ZSTDv07_createDCtx()) */
  75. ZSTDLIB_API size_t ZSTDv07_decompressDCtx(ZSTDv07_DCtx* ctx, void* dst, size_t dstCapacity, const void* src, size_t srcSize);
  76. /*-************************
  77. * Simple dictionary API
  78. ***************************/
  79. /*! ZSTDv07_decompress_usingDict() :
  80. * Decompression using a pre-defined Dictionary content (see dictBuilder).
  81. * Dictionary must be identical to the one used during compression.
  82. * Note : This function load the dictionary, resulting in a significant startup time */
  83. ZSTDLIB_API size_t ZSTDv07_decompress_usingDict(ZSTDv07_DCtx* dctx,
  84. void* dst, size_t dstCapacity,
  85. const void* src, size_t srcSize,
  86. const void* dict,size_t dictSize);
  87. /*-**************************
  88. * Advanced Dictionary API
  89. ****************************/
  90. /*! ZSTDv07_createDDict() :
  91. * Create a digested dictionary, ready to start decompression operation without startup delay.
  92. * `dict` can be released after creation */
  93. typedef struct ZSTDv07_DDict_s ZSTDv07_DDict;
  94. ZSTDLIB_API ZSTDv07_DDict* ZSTDv07_createDDict(const void* dict, size_t dictSize);
  95. ZSTDLIB_API size_t ZSTDv07_freeDDict(ZSTDv07_DDict* ddict);
  96. /*! ZSTDv07_decompress_usingDDict() :
  97. * Decompression using a pre-digested Dictionary
  98. * Faster startup than ZSTDv07_decompress_usingDict(), recommended when same dictionary is used multiple times. */
  99. ZSTDLIB_API size_t ZSTDv07_decompress_usingDDict(ZSTDv07_DCtx* dctx,
  100. void* dst, size_t dstCapacity,
  101. const void* src, size_t srcSize,
  102. const ZSTDv07_DDict* ddict);
  103. typedef struct {
  104. unsigned long long frameContentSize;
  105. unsigned windowSize;
  106. unsigned dictID;
  107. unsigned checksumFlag;
  108. } ZSTDv07_frameParams;
  109. ZSTDLIB_API size_t ZSTDv07_getFrameParams(ZSTDv07_frameParams* fparamsPtr, const void* src, size_t srcSize); /**< doesn't consume input */
  110. /* ***************************************************************
  111. * Compiler specifics
  112. *****************************************************************/
  113. /* ZSTDv07_DLL_EXPORT :
  114. * Enable exporting of functions when building a Windows DLL */
  115. #if defined(_WIN32) && defined(ZSTDv07_DLL_EXPORT) && (ZSTDv07_DLL_EXPORT==1)
  116. # define ZSTDLIB_API __declspec(dllexport)
  117. #else
  118. # define ZSTDLIB_API
  119. #endif
  120. /* *************************************
  121. * Streaming functions
  122. ***************************************/
  123. typedef struct ZBUFFv07_DCtx_s ZBUFFv07_DCtx;
  124. ZSTDLIB_API ZBUFFv07_DCtx* ZBUFFv07_createDCtx(void);
  125. ZSTDLIB_API size_t ZBUFFv07_freeDCtx(ZBUFFv07_DCtx* dctx);
  126. ZSTDLIB_API size_t ZBUFFv07_decompressInit(ZBUFFv07_DCtx* dctx);
  127. ZSTDLIB_API size_t ZBUFFv07_decompressInitDictionary(ZBUFFv07_DCtx* dctx, const void* dict, size_t dictSize);
  128. ZSTDLIB_API size_t ZBUFFv07_decompressContinue(ZBUFFv07_DCtx* dctx,
  129. void* dst, size_t* dstCapacityPtr,
  130. const void* src, size_t* srcSizePtr);
  131. /*-***************************************************************************
  132. * Streaming decompression howto
  133. *
  134. * A ZBUFFv07_DCtx object is required to track streaming operations.
  135. * Use ZBUFFv07_createDCtx() and ZBUFFv07_freeDCtx() to create/release resources.
  136. * Use ZBUFFv07_decompressInit() to start a new decompression operation,
  137. * or ZBUFFv07_decompressInitDictionary() if decompression requires a dictionary.
  138. * Note that ZBUFFv07_DCtx objects can be re-init multiple times.
  139. *
  140. * Use ZBUFFv07_decompressContinue() repetitively to consume your input.
  141. * *srcSizePtr and *dstCapacityPtr can be any size.
  142. * The function will report how many bytes were read or written by modifying *srcSizePtr and *dstCapacityPtr.
  143. * Note that it may not consume the entire input, in which case it's up to the caller to present remaining input again.
  144. * The content of `dst` will be overwritten (up to *dstCapacityPtr) at each function call, so save its content if it matters, or change `dst`.
  145. * @return : a hint to preferred nb of bytes to use as input for next function call (it's only a hint, to help latency),
  146. * or 0 when a frame is completely decoded,
  147. * or an error code, which can be tested using ZBUFFv07_isError().
  148. *
  149. * Hint : recommended buffer sizes (not compulsory) : ZBUFFv07_recommendedDInSize() and ZBUFFv07_recommendedDOutSize()
  150. * output : ZBUFFv07_recommendedDOutSize== 128 KB block size is the internal unit, it ensures it's always possible to write a full block when decoded.
  151. * input : ZBUFFv07_recommendedDInSize == 128KB + 3;
  152. * just follow indications from ZBUFFv07_decompressContinue() to minimize latency. It should always be <= 128 KB + 3 .
  153. * *******************************************************************************/
  154. /* *************************************
  155. * Tool functions
  156. ***************************************/
  157. ZSTDLIB_API unsigned ZBUFFv07_isError(size_t errorCode);
  158. ZSTDLIB_API const char* ZBUFFv07_getErrorName(size_t errorCode);
  159. /** Functions below provide recommended buffer sizes for Compression or Decompression operations.
  160. * These sizes are just hints, they tend to offer better latency */
  161. ZSTDLIB_API size_t ZBUFFv07_recommendedDInSize(void);
  162. ZSTDLIB_API size_t ZBUFFv07_recommendedDOutSize(void);
  163. /*-*************************************
  164. * Constants
  165. ***************************************/
  166. #define ZSTDv07_MAGICNUMBER 0xFD2FB527 /* v0.7 */
  167. #if defined (__cplusplus)
  168. }
  169. #endif
  170. #endif /* ZSTDv07_H_235446 */