zstd_v08.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. #include <contrib/libs/zstd06/renames.h>
  2. /*
  3. zstd_v08 - decoder for 0.8 format
  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 ZSTDv08_H_235446
  31. #define ZSTDv08_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. * ZSTDv08_DLL_EXPORT :
  40. * Enable exporting of functions when building a Windows DLL
  41. */
  42. #if defined(_WIN32) && defined(ZSTDv08_DLL_EXPORT) && (ZSTDv08_DLL_EXPORT==1)
  43. # define ZSTDLIB_API __declspec(dllexport)
  44. #else
  45. # define ZSTDLIB_API
  46. #endif
  47. /* *************************************
  48. * Simple API
  49. ***************************************/
  50. /*! ZSTDv08_getDecompressedSize() :
  51. * @return : decompressed size as a 64-bits value _if known_, 0 otherwise.
  52. * note 1 : decompressed size can be very large (64-bits value),
  53. * potentially larger than what local system can handle as a single memory segment.
  54. * In which case, it's necessary to use streaming mode to decompress data.
  55. * note 2 : decompressed size is an optional field, that may not be present.
  56. * When `return==0`, consider data to decompress could have any size.
  57. * In which case, it's necessary to use streaming mode to decompress data,
  58. * or rely on application's implied limits.
  59. * (For example, it may know that its own data is necessarily cut into blocks <= 16 KB).
  60. * note 3 : decompressed size could be wrong or intentionally modified !
  61. * Always ensure result fits within application's authorized limits !
  62. * Each application can have its own set of conditions.
  63. * If the intention is to decompress public data compressed by zstd command line utility,
  64. * it is recommended to support at least 8 MB for extended compatibility.
  65. * note 4 : when `return==0`, if precise failure cause is needed, use ZSTDv08_getFrameParams() to know more. */
  66. unsigned long long ZSTDv08_getDecompressedSize(const void* src, size_t srcSize);
  67. /*! ZSTDv08_decompress() :
  68. `compressedSize` : must be the _exact_ size of compressed input, otherwise decompression will fail.
  69. `dstCapacity` must be equal or larger than originalSize (see ZSTDv08_getDecompressedSize() ).
  70. If originalSize is unknown, and if there is no implied application-specific limitations,
  71. it's necessary to use streaming mode to decompress data.
  72. @return : the number of bytes decompressed into `dst` (<= `dstCapacity`),
  73. or an errorCode if it fails (which can be tested using ZSTDv08_isError()) */
  74. ZSTDLIB_API size_t ZSTDv08_decompress( void* dst, size_t dstCapacity,
  75. const void* src, size_t compressedSize);
  76. /*====== Helper functions ======*/
  77. ZSTDLIB_API unsigned ZSTDv08_isError(size_t code); /*!< tells if a `size_t` function result is an error code */
  78. ZSTDLIB_API const char* ZSTDv08_getErrorName(size_t code); /*!< provides readable string from an error code */
  79. /*-*************************************
  80. * Explicit memory management
  81. ***************************************/
  82. /** Decompression context */
  83. typedef struct ZSTDv08_DCtx_s ZSTDv08_DCtx; /*< incomplete type */
  84. ZSTDLIB_API ZSTDv08_DCtx* ZSTDv08_createDCtx(void);
  85. ZSTDLIB_API size_t ZSTDv08_freeDCtx(ZSTDv08_DCtx* dctx);
  86. /** ZSTDv08_decompressDCtx() :
  87. * Same as ZSTDv08_decompress(), requires an allocated ZSTDv08_DCtx (see ZSTDv08_createDCtx()) */
  88. ZSTDLIB_API size_t ZSTDv08_decompressDCtx(ZSTDv08_DCtx* ctx, void* dst, size_t dstCapacity, const void* src, size_t srcSize);
  89. /*-************************
  90. * Simple dictionary API
  91. ***************************/
  92. /*! ZSTDv08_decompress_usingDict() :
  93. * Decompression using a predefined Dictionary (see dictBuilder/zdict.h).
  94. * Dictionary must be identical to the one used during compression.
  95. * Note : This function load the dictionary, resulting in a significant startup time */
  96. ZSTDLIB_API size_t ZSTDv08_decompress_usingDict(ZSTDv08_DCtx* dctx,
  97. void* dst, size_t dstCapacity,
  98. const void* src, size_t srcSize,
  99. const void* dict,size_t dictSize);
  100. /*-**************************
  101. * Fast Dictionary API
  102. ****************************/
  103. /*! ZSTDv08_createDDict() :
  104. * Create a digested dictionary, ready to start decompression operation without startup delay.
  105. * `dict` can be released after creation */
  106. typedef struct ZSTDv08_DDict_s ZSTDv08_DDict;
  107. ZSTDLIB_API ZSTDv08_DDict* ZSTDv08_createDDict(const void* dict, size_t dictSize);
  108. ZSTDLIB_API size_t ZSTDv08_freeDDict(ZSTDv08_DDict* ddict);
  109. /*! ZSTDv08_decompress_usingDDict() :
  110. * Decompression using a digested Dictionary
  111. * Faster startup than ZSTDv08_decompress_usingDict(), recommended when same dictionary is used multiple times. */
  112. ZSTDLIB_API size_t ZSTDv08_decompress_usingDDict(ZSTDv08_DCtx* dctx,
  113. void* dst, size_t dstCapacity,
  114. const void* src, size_t srcSize,
  115. const ZSTDv08_DDict* ddict);
  116. typedef struct {
  117. unsigned long long frameContentSize;
  118. unsigned windowSize;
  119. unsigned dictID;
  120. unsigned checksumFlag;
  121. } ZSTDv08_frameParams;
  122. ZSTDLIB_API size_t ZSTDv08_getFrameParams(ZSTDv08_frameParams* fparamsPtr, const void* src, size_t srcSize); /**< doesn't consume input, see details below */
  123. /* ***************************************************************
  124. * Compiler specifics
  125. *****************************************************************/
  126. /* ZSTDv08_DLL_EXPORT :
  127. * Enable exporting of functions when building a Windows DLL */
  128. #if defined(_WIN32) && defined(ZSTDv08_DLL_EXPORT) && (ZSTDv08_DLL_EXPORT==1)
  129. # define ZSTDLIB_API __declspec(dllexport)
  130. #else
  131. # define ZSTDLIB_API
  132. #endif
  133. /* *************************************
  134. * Streaming functions
  135. ***************************************/
  136. /* This is the easier "buffered" streaming API,
  137. * using an internal buffer to lift all restrictions on user-provided buffers
  138. * which can be any size, any place, for both input and output.
  139. * ZBUFF and ZSTD are 100% interoperable,
  140. * frames created by one can be decoded by the other one */
  141. typedef struct ZBUFFv08_DCtx_s ZBUFFv08_DCtx;
  142. ZSTDLIB_API ZBUFFv08_DCtx* ZBUFFv08_createDCtx(void);
  143. ZSTDLIB_API size_t ZBUFFv08_freeDCtx(ZBUFFv08_DCtx* dctx);
  144. ZSTDLIB_API size_t ZBUFFv08_decompressInit(ZBUFFv08_DCtx* dctx);
  145. ZSTDLIB_API size_t ZBUFFv08_decompressInitDictionary(ZBUFFv08_DCtx* dctx, const void* dict, size_t dictSize);
  146. ZSTDLIB_API size_t ZBUFFv08_decompressContinue(ZBUFFv08_DCtx* dctx,
  147. void* dst, size_t* dstCapacityPtr,
  148. const void* src, size_t* srcSizePtr);
  149. /*-***************************************************************************
  150. * Streaming decompression howto
  151. *
  152. * A ZBUFFv08_DCtx object is required to track streaming operations.
  153. * Use ZBUFFv08_createDCtx() and ZBUFFv08_freeDCtx() to create/release resources.
  154. * Use ZBUFFv08_decompressInit() to start a new decompression operation,
  155. * or ZBUFFv08_decompressInitDictionary() if decompression requires a dictionary.
  156. * Note that ZBUFFv08_DCtx objects can be re-init multiple times.
  157. *
  158. * Use ZBUFFv08_decompressContinue() repetitively to consume your input.
  159. * *srcSizePtr and *dstCapacityPtr can be any size.
  160. * The function will report how many bytes were read or written by modifying *srcSizePtr and *dstCapacityPtr.
  161. * Note that it may not consume the entire input, in which case it's up to the caller to present remaining input again.
  162. * The content of `dst` will be overwritten (up to *dstCapacityPtr) at each function call, so save its content if it matters, or change `dst`.
  163. * @return : 0 when a frame is completely decoded and fully flushed,
  164. * 1 when there is still some data left within internal buffer to flush,
  165. * >1 when more data is expected, with value being a suggested next input size (it's just a hint, which helps latency),
  166. * or an error code, which can be tested using ZBUFFv08_isError().
  167. *
  168. * Hint : recommended buffer sizes (not compulsory) : ZBUFFv08_recommendedDInSize() and ZBUFFv08_recommendedDOutSize()
  169. * output : ZBUFFv08_recommendedDOutSize== 128 KB block size is the internal unit, it ensures it's always possible to write a full block when decoded.
  170. * input : ZBUFFv08_recommendedDInSize == 128KB + 3;
  171. * just follow indications from ZBUFFv08_decompressContinue() to minimize latency. It should always be <= 128 KB + 3 .
  172. * *******************************************************************************/
  173. /* *************************************
  174. * Tool functions
  175. ***************************************/
  176. ZSTDLIB_API unsigned ZBUFFv08_isError(size_t errorCode);
  177. ZSTDLIB_API const char* ZBUFFv08_getErrorName(size_t errorCode);
  178. /** Functions below provide recommended buffer sizes for Compression or Decompression operations.
  179. * These sizes are just hints, they tend to offer better latency */
  180. ZSTDLIB_API size_t ZBUFFv08_recommendedDInSize(void);
  181. ZSTDLIB_API size_t ZBUFFv08_recommendedDOutSize(void);
  182. #define ZSTDv08_MAGICNUMBER 0xFD2FB528 /* v0.8 */
  183. #if defined (__cplusplus)
  184. }
  185. #endif
  186. #endif /* ZSTDv08_H_235446 */