zstd.h 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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 ZSTD_H
  31. #define ZSTD_H
  32. #if defined (__cplusplus)
  33. extern "C" {
  34. #endif
  35. /*-*************************************
  36. * Dependencies
  37. ***************************************/
  38. #include <stddef.h> /* size_t */
  39. /*-***************************************************************
  40. * Export parameters
  41. *****************************************************************/
  42. /*!
  43. * ZSTD_DLL_EXPORT :
  44. * Enable exporting of functions when building a Windows DLL
  45. */
  46. #if defined(_WIN32) && defined(ZSTD_DLL_EXPORT) && (ZSTD_DLL_EXPORT==1)
  47. # define ZSTDLIB_API __declspec(dllexport)
  48. #else
  49. # define ZSTDLIB_API
  50. #endif
  51. /* *************************************
  52. * Version
  53. ***************************************/
  54. #define ZSTD_VERSION_MAJOR 0
  55. #define ZSTD_VERSION_MINOR 6
  56. #define ZSTD_VERSION_RELEASE 2
  57. #define ZSTD_LIB_VERSION ZSTD_VERSION_MAJOR.ZSTD_VERSION_MINOR.ZSTD_VERSION_RELEASE
  58. #define ZSTD_QUOTE(str) #str
  59. #define ZSTD_EXPAND_AND_QUOTE(str) ZSTD_QUOTE(str)
  60. #define ZSTD_VERSION_STRING ZSTD_EXPAND_AND_QUOTE(ZSTD_LIB_VERSION)
  61. #define ZSTD_VERSION_NUMBER (ZSTD_VERSION_MAJOR *100*100 + ZSTD_VERSION_MINOR *100 + ZSTD_VERSION_RELEASE)
  62. ZSTDLIB_API unsigned ZSTD_versionNumber (void);
  63. /* *************************************
  64. * Simple functions
  65. ***************************************/
  66. /*! ZSTD_compress() :
  67. Compresses `srcSize` bytes from buffer `src` into buffer `dst` of size `dstCapacity`.
  68. Destination buffer must be already allocated.
  69. Compression runs faster if `dstCapacity` >= `ZSTD_compressBound(srcSize)`.
  70. @return : the number of bytes written into `dst`,
  71. or an error code if it fails (which can be tested using ZSTD_isError()) */
  72. ZSTDLIB_API size_t ZSTD_compress( void* dst, size_t dstCapacity,
  73. const void* src, size_t srcSize,
  74. int compressionLevel);
  75. /*! ZSTD_decompress() :
  76. `compressedSize` : is the _exact_ size of the compressed blob, otherwise decompression will fail.
  77. `dstCapacity` must be large enough, equal or larger than originalSize.
  78. @return : the number of bytes decompressed into `dst` (<= `dstCapacity`),
  79. or an errorCode if it fails (which can be tested using ZSTD_isError()) */
  80. ZSTDLIB_API size_t ZSTD_decompress( void* dst, size_t dstCapacity,
  81. const void* src, size_t compressedSize);
  82. /* *************************************
  83. * Helper functions
  84. ***************************************/
  85. ZSTDLIB_API size_t ZSTD_compressBound(size_t srcSize); /*!< maximum compressed size (worst case scenario) */
  86. /* Error Management */
  87. ZSTDLIB_API unsigned ZSTD_isError(size_t code); /*!< tells if a `size_t` function result is an error code */
  88. ZSTDLIB_API const char* ZSTD_getErrorName(size_t code); /*!< provides readable string for an error code */
  89. /* *************************************
  90. * Explicit memory management
  91. ***************************************/
  92. /** Compression context */
  93. typedef struct ZSTD_CCtx_s ZSTD_CCtx; /*< incomplete type */
  94. ZSTDLIB_API ZSTD_CCtx* ZSTD_createCCtx(void);
  95. ZSTDLIB_API size_t ZSTD_freeCCtx(ZSTD_CCtx* cctx); /*!< @return : errorCode */
  96. /** ZSTD_compressCCtx() :
  97. Same as ZSTD_compress(), but requires an already allocated ZSTD_CCtx (see ZSTD_createCCtx()) */
  98. ZSTDLIB_API size_t ZSTD_compressCCtx(ZSTD_CCtx* ctx, void* dst, size_t dstCapacity, const void* src, size_t srcSize, int compressionLevel);
  99. /** Decompression context */
  100. typedef struct ZSTD_DCtx_s ZSTD_DCtx;
  101. ZSTDLIB_API ZSTD_DCtx* ZSTD_createDCtx(void);
  102. ZSTDLIB_API size_t ZSTD_freeDCtx(ZSTD_DCtx* dctx); /*!< @return : errorCode */
  103. /** ZSTD_decompressDCtx() :
  104. * Same as ZSTD_decompress(), but requires an already allocated ZSTD_DCtx (see ZSTD_createDCtx()) */
  105. ZSTDLIB_API size_t ZSTD_decompressDCtx(ZSTD_DCtx* ctx, void* dst, size_t dstCapacity, const void* src, size_t srcSize);
  106. /*-***********************
  107. * Dictionary API
  108. *************************/
  109. /*! ZSTD_compress_usingDict() :
  110. * Compression using a pre-defined Dictionary content (see dictBuilder).
  111. * Note : dict can be NULL, in which case, it's equivalent to ZSTD_compressCCtx() */
  112. ZSTDLIB_API size_t ZSTD_compress_usingDict(ZSTD_CCtx* ctx,
  113. void* dst, size_t dstCapacity,
  114. const void* src, size_t srcSize,
  115. const void* dict,size_t dictSize,
  116. int compressionLevel);
  117. /*! ZSTD_decompress_usingDict() :
  118. * Decompression using a pre-defined Dictionary content (see dictBuilder).
  119. * Dictionary must be identical to the one used during compression, otherwise regenerated data will be corrupted.
  120. * Note : dict can be NULL, in which case, it's equivalent to ZSTD_decompressDCtx() */
  121. ZSTDLIB_API size_t ZSTD_decompress_usingDict(ZSTD_DCtx* dctx,
  122. void* dst, size_t dstCapacity,
  123. const void* src, size_t srcSize,
  124. const void* dict,size_t dictSize);
  125. #if defined (__cplusplus)
  126. }
  127. #endif
  128. #endif /* ZSTD_H */