inikep | 82057aa | 2016-10-06 13:23:52 +0200 | [diff] [blame] | 1 | /* |
Yann Collet | 4ded9e5 | 2016-08-30 10:04:33 -0700 | [diff] [blame] | 2 | * Copyright (c) 2016-present, Yann Collet, Facebook, Inc. |
| 3 | * All rights reserved. |
| 4 | * |
| 5 | * This source code is licensed under the BSD-style license found in the |
| 6 | * LICENSE file in the root directory of this source tree. An additional grant |
| 7 | * of patent rights can be found in the PATENTS file in the same directory. |
| 8 | */ |
Yann Collet | 4856a00 | 2015-01-24 01:58:16 +0100 | [diff] [blame] | 9 | |
Yann Collet | d3b7f8d | 2016-06-04 19:47:02 +0200 | [diff] [blame] | 10 | #ifndef ZSTD_H_235446 |
| 11 | #define ZSTD_H_235446 |
Yann Collet | 4856a00 | 2015-01-24 01:58:16 +0100 | [diff] [blame] | 12 | |
| 13 | #if defined (__cplusplus) |
| 14 | extern "C" { |
| 15 | #endif |
| 16 | |
inikep | 82057aa | 2016-10-06 13:23:52 +0200 | [diff] [blame] | 17 | /* ====== Dependency ======*/ |
Yann Collet | 4856a00 | 2015-01-24 01:58:16 +0100 | [diff] [blame] | 18 | #include <stddef.h> /* size_t */ |
| 19 | |
| 20 | |
inikep | 82057aa | 2016-10-06 13:23:52 +0200 | [diff] [blame] | 21 | /* ====== Export for Windows ======*/ |
| 22 | /* |
Christophe Chevalier | c6e8453 | 2015-12-07 17:44:09 +0100 | [diff] [blame] | 23 | * ZSTD_DLL_EXPORT : |
Christophe Chevalier | 7b05324 | 2015-12-09 15:48:22 +0100 | [diff] [blame] | 24 | * Enable exporting of functions when building a Windows DLL |
Christophe Chevalier | c6e8453 | 2015-12-07 17:44:09 +0100 | [diff] [blame] | 25 | */ |
Christophe Chevalier | 7b05324 | 2015-12-09 15:48:22 +0100 | [diff] [blame] | 26 | #if defined(_WIN32) && defined(ZSTD_DLL_EXPORT) && (ZSTD_DLL_EXPORT==1) |
| 27 | # define ZSTDLIB_API __declspec(dllexport) |
Christophe Chevalier | c6e8453 | 2015-12-07 17:44:09 +0100 | [diff] [blame] | 28 | #else |
| 29 | # define ZSTDLIB_API |
| 30 | #endif |
| 31 | |
| 32 | |
inikep | 2d26133 | 2016-10-06 16:28:21 +0200 | [diff] [blame] | 33 | /******************************************************************************************************* |
| 34 | Introduction |
| 35 | |
Yann Collet | 37d1300 | 2016-10-24 17:22:12 -0700 | [diff] [blame] | 36 | zstd, short for Zstandard, is a fast lossless compression algorithm, targeting real-time compression scenarios |
inikep | 2d26133 | 2016-10-06 16:28:21 +0200 | [diff] [blame] | 37 | at zlib-level and better compression ratios. The zstd compression library provides in-memory compression and |
| 38 | decompression functions. The library supports compression levels from 1 up to ZSTD_maxCLevel() which is 22. |
Yann Collet | 37d1300 | 2016-10-24 17:22:12 -0700 | [diff] [blame] | 39 | Levels >= 20, labelled `--ultra`, should be used with caution, as they require more memory. |
inikep | 2d26133 | 2016-10-06 16:28:21 +0200 | [diff] [blame] | 40 | Compression can be done in: |
| 41 | - a single step (described as Simple API) |
| 42 | - a single step, reusing a context (described as Explicit memory management) |
Yann Collet | 37d1300 | 2016-10-24 17:22:12 -0700 | [diff] [blame] | 43 | - unbounded multiple steps (described as Streaming compression) |
inikep | 2d26133 | 2016-10-06 16:28:21 +0200 | [diff] [blame] | 44 | The compression ratio achievable on small data can be highly improved using compression with a dictionary in: |
| 45 | - a single step (described as Simple dictionary API) |
Przemyslaw Skibinski | 984b66c | 2016-10-24 15:59:51 +0200 | [diff] [blame] | 46 | - a single step, reusing a dictionary (described as Fast dictionary API) |
inikep | 2d26133 | 2016-10-06 16:28:21 +0200 | [diff] [blame] | 47 | |
Yann Collet | 37d1300 | 2016-10-24 17:22:12 -0700 | [diff] [blame] | 48 | Advanced experimental functions can be accessed using #define ZSTD_STATIC_LINKING_ONLY before including zstd.h. |
| 49 | These APIs shall never be used with a dynamic library. |
inikep | 2d26133 | 2016-10-06 16:28:21 +0200 | [diff] [blame] | 50 | They are not "stable", their definition may change in the future. Only static linking is allowed. |
| 51 | *********************************************************************************************************/ |
| 52 | |
| 53 | /*------ Version ------*/ |
| 54 | ZSTDLIB_API unsigned ZSTD_versionNumber (void); /**< returns version number of ZSTD */ |
| 55 | |
Yann Collet | 901e85f | 2016-08-31 07:51:25 -0700 | [diff] [blame] | 56 | #define ZSTD_VERSION_MAJOR 1 |
Yann Collet | 1eb2fdc | 2016-09-18 12:21:47 +0200 | [diff] [blame] | 57 | #define ZSTD_VERSION_MINOR 1 |
Yann Collet | f52cd03 | 2016-10-11 17:29:27 -0700 | [diff] [blame] | 58 | #define ZSTD_VERSION_RELEASE 1 |
Yann Collet | e02808f | 2016-04-20 22:46:16 +0200 | [diff] [blame] | 59 | |
| 60 | #define ZSTD_LIB_VERSION ZSTD_VERSION_MAJOR.ZSTD_VERSION_MINOR.ZSTD_VERSION_RELEASE |
| 61 | #define ZSTD_QUOTE(str) #str |
| 62 | #define ZSTD_EXPAND_AND_QUOTE(str) ZSTD_QUOTE(str) |
| 63 | #define ZSTD_VERSION_STRING ZSTD_EXPAND_AND_QUOTE(ZSTD_LIB_VERSION) |
| 64 | |
Yann Collet | 213089c | 2015-06-18 07:43:16 -0800 | [diff] [blame] | 65 | #define ZSTD_VERSION_NUMBER (ZSTD_VERSION_MAJOR *100*100 + ZSTD_VERSION_MINOR *100 + ZSTD_VERSION_RELEASE) |
Yann Collet | 4856a00 | 2015-01-24 01:58:16 +0100 | [diff] [blame] | 66 | |
| 67 | |
inikep | 82057aa | 2016-10-06 13:23:52 +0200 | [diff] [blame] | 68 | /*************************************** |
Yann Collet | cf05b9d | 2016-07-18 16:52:10 +0200 | [diff] [blame] | 69 | * Simple API |
Yann Collet | 7010c27 | 2015-10-21 09:07:25 +0100 | [diff] [blame] | 70 | ***************************************/ |
Yann Collet | 953ce72 | 2016-02-04 15:28:14 +0100 | [diff] [blame] | 71 | /*! ZSTD_compress() : |
Yann Collet | ac175d4 | 2016-09-13 00:51:47 +0200 | [diff] [blame] | 72 | Compresses `src` content as a single zstd compressed frame into already allocated `dst`. |
Yann Collet | cf05b9d | 2016-07-18 16:52:10 +0200 | [diff] [blame] | 73 | Hint : compression runs faster if `dstCapacity` >= `ZSTD_compressBound(srcSize)`. |
Yann Collet | 64deef3 | 2016-09-14 00:16:07 +0200 | [diff] [blame] | 74 | @return : compressed size written into `dst` (<= `dstCapacity), |
Nick Terrell | d82efd8 | 2016-11-02 16:47:53 -0700 | [diff] [blame^] | 75 | or an error code if it fails (which can be tested using ZSTD_isError()). */ |
Yann Collet | cf05b9d | 2016-07-18 16:52:10 +0200 | [diff] [blame] | 76 | ZSTDLIB_API size_t ZSTD_compress( void* dst, size_t dstCapacity, |
| 77 | const void* src, size_t srcSize, |
| 78 | int compressionLevel); |
Yann Collet | 4856a00 | 2015-01-24 01:58:16 +0100 | [diff] [blame] | 79 | |
Yann Collet | 953ce72 | 2016-02-04 15:28:14 +0100 | [diff] [blame] | 80 | /*! ZSTD_decompress() : |
Yann Collet | ac175d4 | 2016-09-13 00:51:47 +0200 | [diff] [blame] | 81 | `compressedSize` : must be the _exact_ size of a single compressed frame. |
| 82 | `dstCapacity` is an upper bound of originalSize. |
| 83 | If user cannot imply a maximum upper bound, it's better to use streaming mode to decompress data. |
Yann Collet | 953ce72 | 2016-02-04 15:28:14 +0100 | [diff] [blame] | 84 | @return : the number of bytes decompressed into `dst` (<= `dstCapacity`), |
Nick Terrell | d82efd8 | 2016-11-02 16:47:53 -0700 | [diff] [blame^] | 85 | or an errorCode if it fails (which can be tested using ZSTD_isError()). */ |
Yann Collet | 7d968c7 | 2016-02-03 02:11:32 +0100 | [diff] [blame] | 86 | ZSTDLIB_API size_t ZSTD_decompress( void* dst, size_t dstCapacity, |
Christophe Chevalier | c6e8453 | 2015-12-07 17:44:09 +0100 | [diff] [blame] | 87 | const void* src, size_t compressedSize); |
Yann Collet | 4856a00 | 2015-01-24 01:58:16 +0100 | [diff] [blame] | 88 | |
Yann Collet | ac175d4 | 2016-09-13 00:51:47 +0200 | [diff] [blame] | 89 | /*! ZSTD_getDecompressedSize() : |
| 90 | * 'src' is the start of a zstd compressed frame. |
| 91 | * @return : content size to be decompressed, as a 64-bits value _if known_, 0 otherwise. |
| 92 | * note 1 : decompressed size is an optional field, that may not be present, especially in streaming mode. |
| 93 | * When `return==0`, data to decompress could be any size. |
| 94 | * In which case, it's necessary to use streaming mode to decompress data. |
| 95 | * Optionally, application can still use ZSTD_decompress() while relying on implied limits. |
| 96 | * (For example, data may be necessarily cut into blocks <= 16 KB). |
| 97 | * note 2 : decompressed size is always present when compression is done with ZSTD_compress() |
| 98 | * note 3 : decompressed size can be very large (64-bits value), |
| 99 | * potentially larger than what local system can handle as a single memory segment. |
| 100 | * In which case, it's necessary to use streaming mode to decompress data. |
| 101 | * note 4 : If source is untrusted, decompressed size could be wrong or intentionally modified. |
| 102 | * Always ensure result fits within application's authorized limits. |
| 103 | * Each application can set its own limits. |
| 104 | * note 5 : when `return==0`, if precise failure cause is needed, use ZSTD_getFrameParams() to know more. */ |
| 105 | ZSTDLIB_API unsigned long long ZSTD_getDecompressedSize(const void* src, size_t srcSize); |
| 106 | |
Yann Collet | 4110534 | 2016-07-27 15:09:11 +0200 | [diff] [blame] | 107 | |
Yann Collet | cf05b9d | 2016-07-18 16:52:10 +0200 | [diff] [blame] | 108 | /*====== Helper functions ======*/ |
Yann Collet | 4110534 | 2016-07-27 15:09:11 +0200 | [diff] [blame] | 109 | ZSTDLIB_API int ZSTD_maxCLevel(void); /*!< maximum compression level available */ |
| 110 | ZSTDLIB_API size_t ZSTD_compressBound(size_t srcSize); /*!< maximum compressed size in worst case scenario */ |
Yann Collet | 953ce72 | 2016-02-04 15:28:14 +0100 | [diff] [blame] | 111 | ZSTDLIB_API unsigned ZSTD_isError(size_t code); /*!< tells if a `size_t` function result is an error code */ |
Yann Collet | cf05b9d | 2016-07-18 16:52:10 +0200 | [diff] [blame] | 112 | ZSTDLIB_API const char* ZSTD_getErrorName(size_t code); /*!< provides readable string from an error code */ |
Yann Collet | 7010c27 | 2015-10-21 09:07:25 +0100 | [diff] [blame] | 113 | |
| 114 | |
inikep | 82057aa | 2016-10-06 13:23:52 +0200 | [diff] [blame] | 115 | /*************************************** |
Yann Collet | 7d968c7 | 2016-02-03 02:11:32 +0100 | [diff] [blame] | 116 | * Explicit memory management |
Yann Collet | 7010c27 | 2015-10-21 09:07:25 +0100 | [diff] [blame] | 117 | ***************************************/ |
Yann Collet | 37d1300 | 2016-10-24 17:22:12 -0700 | [diff] [blame] | 118 | /*= Compression context |
| 119 | * When compressing many messages / blocks, |
| 120 | * it is recommended to allocate a context just once, and re-use it for each successive compression operation. |
| 121 | * This will make the situation much easier for the system's memory. |
| 122 | * Use one context per thread for parallel execution in multi-threaded environments. */ |
Yann Collet | 87c18b2 | 2016-08-26 01:43:47 +0200 | [diff] [blame] | 123 | typedef struct ZSTD_CCtx_s ZSTD_CCtx; |
Christophe Chevalier | c6e8453 | 2015-12-07 17:44:09 +0100 | [diff] [blame] | 124 | ZSTDLIB_API ZSTD_CCtx* ZSTD_createCCtx(void); |
Yann Collet | d469a98 | 2016-07-28 03:47:45 +0200 | [diff] [blame] | 125 | ZSTDLIB_API size_t ZSTD_freeCCtx(ZSTD_CCtx* cctx); |
Yann Collet | 7010c27 | 2015-10-21 09:07:25 +0100 | [diff] [blame] | 126 | |
inikep | 82057aa | 2016-10-06 13:23:52 +0200 | [diff] [blame] | 127 | /*! ZSTD_compressCCtx() : |
Nick Terrell | d82efd8 | 2016-11-02 16:47:53 -0700 | [diff] [blame^] | 128 | Same as ZSTD_compress(), requires an allocated ZSTD_CCtx (see ZSTD_createCCtx()). */ |
Yann Collet | 7d968c7 | 2016-02-03 02:11:32 +0100 | [diff] [blame] | 129 | ZSTDLIB_API size_t ZSTD_compressCCtx(ZSTD_CCtx* ctx, void* dst, size_t dstCapacity, const void* src, size_t srcSize, int compressionLevel); |
Yann Collet | 4856a00 | 2015-01-24 01:58:16 +0100 | [diff] [blame] | 130 | |
inikep | 82057aa | 2016-10-06 13:23:52 +0200 | [diff] [blame] | 131 | /*= Decompression context */ |
Yann Collet | 87c18b2 | 2016-08-26 01:43:47 +0200 | [diff] [blame] | 132 | typedef struct ZSTD_DCtx_s ZSTD_DCtx; |
Yann Collet | ecd651b | 2016-01-07 15:35:18 +0100 | [diff] [blame] | 133 | ZSTDLIB_API ZSTD_DCtx* ZSTD_createDCtx(void); |
Yann Collet | d469a98 | 2016-07-28 03:47:45 +0200 | [diff] [blame] | 134 | ZSTDLIB_API size_t ZSTD_freeDCtx(ZSTD_DCtx* dctx); |
Yann Collet | ecd651b | 2016-01-07 15:35:18 +0100 | [diff] [blame] | 135 | |
inikep | 82057aa | 2016-10-06 13:23:52 +0200 | [diff] [blame] | 136 | /*! ZSTD_decompressDCtx() : |
Nick Terrell | d82efd8 | 2016-11-02 16:47:53 -0700 | [diff] [blame^] | 137 | * Same as ZSTD_decompress(), requires an allocated ZSTD_DCtx (see ZSTD_createDCtx()). */ |
Yann Collet | 7d968c7 | 2016-02-03 02:11:32 +0100 | [diff] [blame] | 138 | ZSTDLIB_API size_t ZSTD_decompressDCtx(ZSTD_DCtx* ctx, void* dst, size_t dstCapacity, const void* src, size_t srcSize); |
| 139 | |
| 140 | |
inikep | 82057aa | 2016-10-06 13:23:52 +0200 | [diff] [blame] | 141 | /************************** |
Yann Collet | 302fb53 | 2016-06-07 12:16:49 +0200 | [diff] [blame] | 142 | * Simple dictionary API |
| 143 | ***************************/ |
Yann Collet | 953ce72 | 2016-02-04 15:28:14 +0100 | [diff] [blame] | 144 | /*! ZSTD_compress_usingDict() : |
Yann Collet | d469a98 | 2016-07-28 03:47:45 +0200 | [diff] [blame] | 145 | * Compression using a predefined Dictionary (see dictBuilder/zdict.h). |
Nick Terrell | d82efd8 | 2016-11-02 16:47:53 -0700 | [diff] [blame^] | 146 | * Note : This function loads the dictionary, resulting in significant startup delay. |
| 147 | * Note : When `dict == NULL || dictSize < 8` no dictionary is used. */ |
Yann Collet | 7d968c7 | 2016-02-03 02:11:32 +0100 | [diff] [blame] | 148 | ZSTDLIB_API size_t ZSTD_compress_usingDict(ZSTD_CCtx* ctx, |
| 149 | void* dst, size_t dstCapacity, |
| 150 | const void* src, size_t srcSize, |
| 151 | const void* dict,size_t dictSize, |
| 152 | int compressionLevel); |
| 153 | |
Yann Collet | 953ce72 | 2016-02-04 15:28:14 +0100 | [diff] [blame] | 154 | /*! ZSTD_decompress_usingDict() : |
Yann Collet | d469a98 | 2016-07-28 03:47:45 +0200 | [diff] [blame] | 155 | * Decompression using a predefined Dictionary (see dictBuilder/zdict.h). |
Yann Collet | 81e13ef | 2016-06-07 00:51:51 +0200 | [diff] [blame] | 156 | * Dictionary must be identical to the one used during compression. |
Nick Terrell | d82efd8 | 2016-11-02 16:47:53 -0700 | [diff] [blame^] | 157 | * Note : This function loads the dictionary, resulting in significant startup delay. |
| 158 | * Note : When `dict == NULL || dictSize < 8` no dictionary is used. */ |
Yann Collet | 7d968c7 | 2016-02-03 02:11:32 +0100 | [diff] [blame] | 159 | ZSTDLIB_API size_t ZSTD_decompress_usingDict(ZSTD_DCtx* dctx, |
| 160 | void* dst, size_t dstCapacity, |
| 161 | const void* src, size_t srcSize, |
| 162 | const void* dict,size_t dictSize); |
Yann Collet | ecd651b | 2016-01-07 15:35:18 +0100 | [diff] [blame] | 163 | |
Yann Collet | 4856a00 | 2015-01-24 01:58:16 +0100 | [diff] [blame] | 164 | |
inikep | 82057aa | 2016-10-06 13:23:52 +0200 | [diff] [blame] | 165 | /**************************** |
Przemyslaw Skibinski | 984b66c | 2016-10-24 15:59:51 +0200 | [diff] [blame] | 166 | * Fast dictionary API |
Yann Collet | 302fb53 | 2016-06-07 12:16:49 +0200 | [diff] [blame] | 167 | ****************************/ |
inikep | 2d26133 | 2016-10-06 16:28:21 +0200 | [diff] [blame] | 168 | typedef struct ZSTD_CDict_s ZSTD_CDict; |
| 169 | |
Yann Collet | 302fb53 | 2016-06-07 12:16:49 +0200 | [diff] [blame] | 170 | /*! ZSTD_createCDict() : |
Yann Collet | 37d1300 | 2016-10-24 17:22:12 -0700 | [diff] [blame] | 171 | * When compressing multiple messages / blocks with the same dictionary, it's recommended to load it just once. |
| 172 | * ZSTD_createCDict() will create a digested dictionary, ready to start future compression operations without startup delay. |
| 173 | * ZSTD_CDict can be created once and used by multiple threads concurrently, as its usage is read-only. |
Nick Terrell | d82efd8 | 2016-11-02 16:47:53 -0700 | [diff] [blame^] | 174 | * `dict` can be released after ZSTD_CDict creation. */ |
Yann Collet | 302fb53 | 2016-06-07 12:16:49 +0200 | [diff] [blame] | 175 | ZSTDLIB_API ZSTD_CDict* ZSTD_createCDict(const void* dict, size_t dictSize, int compressionLevel); |
inikep | 2d26133 | 2016-10-06 16:28:21 +0200 | [diff] [blame] | 176 | |
| 177 | /*! ZSTD_freeCDict() : |
Nick Terrell | d82efd8 | 2016-11-02 16:47:53 -0700 | [diff] [blame^] | 178 | * Function frees memory allocated by ZSTD_createCDict(). */ |
Yann Collet | 302fb53 | 2016-06-07 12:16:49 +0200 | [diff] [blame] | 179 | ZSTDLIB_API size_t ZSTD_freeCDict(ZSTD_CDict* CDict); |
| 180 | |
| 181 | /*! ZSTD_compress_usingCDict() : |
Yann Collet | d469a98 | 2016-07-28 03:47:45 +0200 | [diff] [blame] | 182 | * Compression using a digested Dictionary. |
Yann Collet | cf05b9d | 2016-07-18 16:52:10 +0200 | [diff] [blame] | 183 | * Faster startup than ZSTD_compress_usingDict(), recommended when same dictionary is used multiple times. |
Nick Terrell | d82efd8 | 2016-11-02 16:47:53 -0700 | [diff] [blame^] | 184 | * Note that compression level is decided during dictionary creation. */ |
Yann Collet | 302fb53 | 2016-06-07 12:16:49 +0200 | [diff] [blame] | 185 | ZSTDLIB_API size_t ZSTD_compress_usingCDict(ZSTD_CCtx* cctx, |
| 186 | void* dst, size_t dstCapacity, |
| 187 | const void* src, size_t srcSize, |
| 188 | const ZSTD_CDict* cdict); |
| 189 | |
inikep | 2d26133 | 2016-10-06 16:28:21 +0200 | [diff] [blame] | 190 | |
| 191 | typedef struct ZSTD_DDict_s ZSTD_DDict; |
| 192 | |
Yann Collet | 302fb53 | 2016-06-07 12:16:49 +0200 | [diff] [blame] | 193 | /*! ZSTD_createDDict() : |
| 194 | * Create a digested dictionary, ready to start decompression operation without startup delay. |
Nick Terrell | d82efd8 | 2016-11-02 16:47:53 -0700 | [diff] [blame^] | 195 | * `dict` can be released after creation. */ |
Yann Collet | 302fb53 | 2016-06-07 12:16:49 +0200 | [diff] [blame] | 196 | ZSTDLIB_API ZSTD_DDict* ZSTD_createDDict(const void* dict, size_t dictSize); |
inikep | 2d26133 | 2016-10-06 16:28:21 +0200 | [diff] [blame] | 197 | |
| 198 | /*! ZSTD_freeDDict() : |
| 199 | * Function frees memory allocated with ZSTD_createDDict() */ |
Yann Collet | 302fb53 | 2016-06-07 12:16:49 +0200 | [diff] [blame] | 200 | ZSTDLIB_API size_t ZSTD_freeDDict(ZSTD_DDict* ddict); |
| 201 | |
| 202 | /*! ZSTD_decompress_usingDDict() : |
Nick Terrell | d82efd8 | 2016-11-02 16:47:53 -0700 | [diff] [blame^] | 203 | * Decompression using a digested Dictionary. |
Yann Collet | cf05b9d | 2016-07-18 16:52:10 +0200 | [diff] [blame] | 204 | * Faster startup than ZSTD_decompress_usingDict(), recommended when same dictionary is used multiple times. */ |
Yann Collet | 302fb53 | 2016-06-07 12:16:49 +0200 | [diff] [blame] | 205 | ZSTDLIB_API size_t ZSTD_decompress_usingDDict(ZSTD_DCtx* dctx, |
| 206 | void* dst, size_t dstCapacity, |
| 207 | const void* src, size_t srcSize, |
| 208 | const ZSTD_DDict* ddict); |
| 209 | |
| 210 | |
inikep | 82057aa | 2016-10-06 13:23:52 +0200 | [diff] [blame] | 211 | /**************************** |
Yann Collet | 7be46bf | 2016-08-19 18:39:36 +0200 | [diff] [blame] | 212 | * Streaming |
| 213 | ****************************/ |
| 214 | |
| 215 | typedef struct ZSTD_inBuffer_s { |
| 216 | const void* src; /**< start of input buffer */ |
| 217 | size_t size; /**< size of input buffer */ |
| 218 | size_t pos; /**< position where reading stopped. Will be updated. Necessarily 0 <= pos <= size */ |
| 219 | } ZSTD_inBuffer; |
| 220 | |
| 221 | typedef struct ZSTD_outBuffer_s { |
| 222 | void* dst; /**< start of output buffer */ |
| 223 | size_t size; /**< size of output buffer */ |
| 224 | size_t pos; /**< position where writing stopped. Will be updated. Necessarily 0 <= pos <= size */ |
| 225 | } ZSTD_outBuffer; |
| 226 | |
| 227 | |
Yann Collet | 7be46bf | 2016-08-19 18:39:36 +0200 | [diff] [blame] | 228 | |
inikep | ba1db37 | 2016-10-06 14:22:48 +0200 | [diff] [blame] | 229 | /*-*********************************************************************** |
Przemyslaw Skibinski | 984b66c | 2016-10-24 15:59:51 +0200 | [diff] [blame] | 230 | * Streaming compression - HowTo |
Yann Collet | 7be46bf | 2016-08-19 18:39:36 +0200 | [diff] [blame] | 231 | * |
| 232 | * A ZSTD_CStream object is required to track streaming operation. |
| 233 | * Use ZSTD_createCStream() and ZSTD_freeCStream() to create/release resources. |
| 234 | * ZSTD_CStream objects can be reused multiple times on consecutive compression operations. |
Yann Collet | 37d1300 | 2016-10-24 17:22:12 -0700 | [diff] [blame] | 235 | * It is recommended to re-use ZSTD_CStream in situations where many streaming operations will be achieved consecutively, |
| 236 | * since it will play nicer with system's memory, by re-using already allocated memory. |
| 237 | * Use one separate ZSTD_CStream per thread for parallel execution. |
Yann Collet | 7be46bf | 2016-08-19 18:39:36 +0200 | [diff] [blame] | 238 | * |
Yann Collet | 37d1300 | 2016-10-24 17:22:12 -0700 | [diff] [blame] | 239 | * Start a new compression by initializing ZSTD_CStream. |
Yann Collet | 7be46bf | 2016-08-19 18:39:36 +0200 | [diff] [blame] | 240 | * Use ZSTD_initCStream() to start a new compression operation. |
| 241 | * Use ZSTD_initCStream_usingDict() for a compression which requires a dictionary. |
| 242 | * |
| 243 | * Use ZSTD_compressStream() repetitively to consume input stream. |
Yann Collet | fa72f6b | 2016-09-05 17:39:56 +0200 | [diff] [blame] | 244 | * The function will automatically update both `pos` fields. |
Yann Collet | 7be46bf | 2016-08-19 18:39:36 +0200 | [diff] [blame] | 245 | * Note that it may not consume the entire input, in which case `pos < size`, |
| 246 | * and it's up to the caller to present again remaining data. |
Yann Collet | 4bf317d | 2016-08-28 07:43:34 -0700 | [diff] [blame] | 247 | * @return : a size hint, preferred nb of bytes to use as input for next function call |
| 248 | * (it's just a hint, to help latency a little, any other value will work fine) |
| 249 | * (note : the size hint is guaranteed to be <= ZSTD_CStreamInSize() ) |
Yann Collet | 7be46bf | 2016-08-19 18:39:36 +0200 | [diff] [blame] | 250 | * or an error code, which can be tested using ZSTD_isError(). |
| 251 | * |
| 252 | * At any moment, it's possible to flush whatever data remains within buffer, using ZSTD_flushStream(). |
| 253 | * `output->pos` will be updated. |
| 254 | * Note some content might still be left within internal buffer if `output->size` is too small. |
| 255 | * @return : nb of bytes still present within internal buffer (0 if it's empty) |
| 256 | * or an error code, which can be tested using ZSTD_isError(). |
| 257 | * |
| 258 | * ZSTD_endStream() instructs to finish a frame. |
| 259 | * It will perform a flush and write frame epilogue. |
| 260 | * The epilogue is required for decoders to consider a frame completed. |
| 261 | * Similar to ZSTD_flushStream(), it may not be able to flush the full content if `output->size` is too small. |
| 262 | * In which case, call again ZSTD_endStream() to complete the flush. |
| 263 | * @return : nb of bytes still present within internal buffer (0 if it's empty) |
| 264 | * or an error code, which can be tested using ZSTD_isError(). |
| 265 | * |
| 266 | * *******************************************************************/ |
| 267 | |
inikep | 82057aa | 2016-10-06 13:23:52 +0200 | [diff] [blame] | 268 | /*===== Streaming compression functions ======*/ |
Yann Collet | 7be46bf | 2016-08-19 18:39:36 +0200 | [diff] [blame] | 269 | typedef struct ZSTD_CStream_s ZSTD_CStream; |
Yann Collet | 70e3b31 | 2016-08-23 01:18:06 +0200 | [diff] [blame] | 270 | ZSTDLIB_API ZSTD_CStream* ZSTD_createCStream(void); |
| 271 | ZSTDLIB_API size_t ZSTD_freeCStream(ZSTD_CStream* zcs); |
Yann Collet | 70e3b31 | 2016-08-23 01:18:06 +0200 | [diff] [blame] | 272 | ZSTDLIB_API size_t ZSTD_initCStream(ZSTD_CStream* zcs, int compressionLevel); |
| 273 | ZSTDLIB_API size_t ZSTD_compressStream(ZSTD_CStream* zcs, ZSTD_outBuffer* output, ZSTD_inBuffer* input); |
| 274 | ZSTDLIB_API size_t ZSTD_flushStream(ZSTD_CStream* zcs, ZSTD_outBuffer* output); |
| 275 | ZSTDLIB_API size_t ZSTD_endStream(ZSTD_CStream* zcs, ZSTD_outBuffer* output); |
Yann Collet | 7be46bf | 2016-08-19 18:39:36 +0200 | [diff] [blame] | 276 | |
inikep | 82057aa | 2016-10-06 13:23:52 +0200 | [diff] [blame] | 277 | ZSTDLIB_API size_t ZSTD_CStreamInSize(void); /**< recommended size for input buffer */ |
| 278 | ZSTDLIB_API size_t ZSTD_CStreamOutSize(void); /**< recommended size for output buffer. Guarantee to successfully flush at least one complete compressed block in all circumstances. */ |
Yann Collet | 7be46bf | 2016-08-19 18:39:36 +0200 | [diff] [blame] | 279 | |
Yann Collet | 7be46bf | 2016-08-19 18:39:36 +0200 | [diff] [blame] | 280 | |
inikep | 82057aa | 2016-10-06 13:23:52 +0200 | [diff] [blame] | 281 | |
inikep | ba1db37 | 2016-10-06 14:22:48 +0200 | [diff] [blame] | 282 | /*-*************************************************************************** |
Przemyslaw Skibinski | 984b66c | 2016-10-24 15:59:51 +0200 | [diff] [blame] | 283 | * Streaming decompression - HowTo |
Yann Collet | 7be46bf | 2016-08-19 18:39:36 +0200 | [diff] [blame] | 284 | * |
| 285 | * A ZSTD_DStream object is required to track streaming operations. |
| 286 | * Use ZSTD_createDStream() and ZSTD_freeDStream() to create/release resources. |
Yann Collet | 17e482e | 2016-08-23 16:58:10 +0200 | [diff] [blame] | 287 | * ZSTD_DStream objects can be re-used multiple times. |
Yann Collet | 7be46bf | 2016-08-19 18:39:36 +0200 | [diff] [blame] | 288 | * |
| 289 | * Use ZSTD_initDStream() to start a new decompression operation, |
| 290 | * or ZSTD_initDStream_usingDict() if decompression requires a dictionary. |
Yann Collet | 7c83dfd | 2016-09-05 19:47:43 +0200 | [diff] [blame] | 291 | * @return : recommended first input size |
Yann Collet | 7be46bf | 2016-08-19 18:39:36 +0200 | [diff] [blame] | 292 | * |
| 293 | * Use ZSTD_decompressStream() repetitively to consume your input. |
Yann Collet | fa72f6b | 2016-09-05 17:39:56 +0200 | [diff] [blame] | 294 | * The function will update both `pos` fields. |
Yann Collet | b3060f7 | 2016-09-09 16:44:16 +0200 | [diff] [blame] | 295 | * If `input.pos < input.size`, some input has not been consumed. |
Yann Collet | 1d4208c | 2016-09-06 05:16:40 +0200 | [diff] [blame] | 296 | * It's up to the caller to present again remaining data. |
Yann Collet | b3060f7 | 2016-09-09 16:44:16 +0200 | [diff] [blame] | 297 | * If `output.pos < output.size`, decoder has flushed everything it could. |
Yann Collet | 7be46bf | 2016-08-19 18:39:36 +0200 | [diff] [blame] | 298 | * @return : 0 when a frame is completely decoded and fully flushed, |
Yann Collet | fa72f6b | 2016-09-05 17:39:56 +0200 | [diff] [blame] | 299 | * an error code, which can be tested using ZSTD_isError(), |
Yann Collet | b3060f7 | 2016-09-09 16:44:16 +0200 | [diff] [blame] | 300 | * any other value > 0, which means there is still some work to do to complete the frame. |
| 301 | * The return value is a suggested next input size (just an hint, to help latency). |
Yann Collet | 7be46bf | 2016-08-19 18:39:36 +0200 | [diff] [blame] | 302 | * *******************************************************************************/ |
| 303 | |
inikep | 82057aa | 2016-10-06 13:23:52 +0200 | [diff] [blame] | 304 | /*===== Streaming decompression functions =====*/ |
Yann Collet | 7be46bf | 2016-08-19 18:39:36 +0200 | [diff] [blame] | 305 | typedef struct ZSTD_DStream_s ZSTD_DStream; |
Yann Collet | 70e3b31 | 2016-08-23 01:18:06 +0200 | [diff] [blame] | 306 | ZSTDLIB_API ZSTD_DStream* ZSTD_createDStream(void); |
| 307 | ZSTDLIB_API size_t ZSTD_freeDStream(ZSTD_DStream* zds); |
inikep | 82057aa | 2016-10-06 13:23:52 +0200 | [diff] [blame] | 308 | ZSTDLIB_API size_t ZSTD_initDStream(ZSTD_DStream* zds); |
| 309 | ZSTDLIB_API size_t ZSTD_decompressStream(ZSTD_DStream* zds, ZSTD_outBuffer* output, ZSTD_inBuffer* input); |
Yann Collet | 7be46bf | 2016-08-19 18:39:36 +0200 | [diff] [blame] | 310 | |
Yann Collet | 70e3b31 | 2016-08-23 01:18:06 +0200 | [diff] [blame] | 311 | ZSTDLIB_API size_t ZSTD_DStreamInSize(void); /*!< recommended size for input buffer */ |
Yann Collet | 01c1992 | 2016-09-08 19:29:04 +0200 | [diff] [blame] | 312 | ZSTDLIB_API size_t ZSTD_DStreamOutSize(void); /*!< recommended size for output buffer. Guarantee to successfully flush at least one complete block in all circumstances. */ |
Yann Collet | 7be46bf | 2016-08-19 18:39:36 +0200 | [diff] [blame] | 313 | |
Yann Collet | 7be46bf | 2016-08-19 18:39:36 +0200 | [diff] [blame] | 314 | |
| 315 | |
Yann Collet | d3b7f8d | 2016-06-04 19:47:02 +0200 | [diff] [blame] | 316 | #ifdef ZSTD_STATIC_LINKING_ONLY |
| 317 | |
inikep | 82057aa | 2016-10-06 13:23:52 +0200 | [diff] [blame] | 318 | /**************************************************************************************** |
inikep | 2d26133 | 2016-10-06 16:28:21 +0200 | [diff] [blame] | 319 | * START OF ADVANCED AND EXPERIMENTAL FUNCTIONS |
Yann Collet | d3b7f8d | 2016-06-04 19:47:02 +0200 | [diff] [blame] | 320 | * The definitions in this section are considered experimental. |
Yann Collet | a49e066 | 2016-06-21 11:54:03 +0200 | [diff] [blame] | 321 | * They should never be used with a dynamic library, as they may change in the future. |
Yann Collet | d3b7f8d | 2016-06-04 19:47:02 +0200 | [diff] [blame] | 322 | * They are provided for advanced usages. |
| 323 | * Use them only in association with static linking. |
inikep | 82057aa | 2016-10-06 13:23:52 +0200 | [diff] [blame] | 324 | * ***************************************************************************************/ |
Yann Collet | d3b7f8d | 2016-06-04 19:47:02 +0200 | [diff] [blame] | 325 | |
inikep | 82057aa | 2016-10-06 13:23:52 +0200 | [diff] [blame] | 326 | /* --- Constants ---*/ |
Yann Collet | 7bf72bb | 2016-07-20 13:36:43 +0200 | [diff] [blame] | 327 | #define ZSTD_MAGICNUMBER 0xFD2FB528 /* v0.8 */ |
Yann Collet | d3b7f8d | 2016-06-04 19:47:02 +0200 | [diff] [blame] | 328 | #define ZSTD_MAGIC_SKIPPABLE_START 0x184D2A50U |
| 329 | |
Yann Collet | ed3845d | 2016-07-08 12:57:10 +0200 | [diff] [blame] | 330 | #define ZSTD_WINDOWLOG_MAX_32 25 |
| 331 | #define ZSTD_WINDOWLOG_MAX_64 27 |
| 332 | #define ZSTD_WINDOWLOG_MAX ((U32)(MEM_32bits() ? ZSTD_WINDOWLOG_MAX_32 : ZSTD_WINDOWLOG_MAX_64)) |
Yann Collet | cf409a7 | 2016-09-26 16:41:05 +0200 | [diff] [blame] | 333 | #define ZSTD_WINDOWLOG_MIN 10 |
Yann Collet | d3b7f8d | 2016-06-04 19:47:02 +0200 | [diff] [blame] | 334 | #define ZSTD_HASHLOG_MAX ZSTD_WINDOWLOG_MAX |
Yann Collet | cf409a7 | 2016-09-26 16:41:05 +0200 | [diff] [blame] | 335 | #define ZSTD_HASHLOG_MIN 6 |
| 336 | #define ZSTD_CHAINLOG_MAX (ZSTD_WINDOWLOG_MAX+1) |
| 337 | #define ZSTD_CHAINLOG_MIN ZSTD_HASHLOG_MIN |
Yann Collet | d3b7f8d | 2016-06-04 19:47:02 +0200 | [diff] [blame] | 338 | #define ZSTD_HASHLOG3_MAX 17 |
Yann Collet | d3b7f8d | 2016-06-04 19:47:02 +0200 | [diff] [blame] | 339 | #define ZSTD_SEARCHLOG_MAX (ZSTD_WINDOWLOG_MAX-1) |
| 340 | #define ZSTD_SEARCHLOG_MIN 1 |
Yann Collet | 0e07bf3 | 2016-09-07 06:33:02 +0200 | [diff] [blame] | 341 | #define ZSTD_SEARCHLENGTH_MAX 7 /* only for ZSTD_fast, other strategies are limited to 6 */ |
| 342 | #define ZSTD_SEARCHLENGTH_MIN 3 /* only for ZSTD_btopt, other strategies are limited to 4 */ |
Yann Collet | d3b7f8d | 2016-06-04 19:47:02 +0200 | [diff] [blame] | 343 | #define ZSTD_TARGETLENGTH_MIN 4 |
| 344 | #define ZSTD_TARGETLENGTH_MAX 999 |
| 345 | |
Yann Collet | 673f0d7 | 2016-06-06 00:26:38 +0200 | [diff] [blame] | 346 | #define ZSTD_FRAMEHEADERSIZE_MAX 18 /* for static allocation */ |
Yann Collet | 7c83dfd | 2016-09-05 19:47:43 +0200 | [diff] [blame] | 347 | static const size_t ZSTD_frameHeaderSize_prefix = 5; |
| 348 | static const size_t ZSTD_frameHeaderSize_min = 6; |
Yann Collet | 673f0d7 | 2016-06-06 00:26:38 +0200 | [diff] [blame] | 349 | static const size_t ZSTD_frameHeaderSize_max = ZSTD_FRAMEHEADERSIZE_MAX; |
| 350 | static const size_t ZSTD_skippableHeaderSize = 8; /* magic number + skippable frame length */ |
| 351 | |
Yann Collet | d3b7f8d | 2016-06-04 19:47:02 +0200 | [diff] [blame] | 352 | |
Przemyslaw Skibinski | 984b66c | 2016-10-24 15:59:51 +0200 | [diff] [blame] | 353 | /*--- Advanced types ---*/ |
Przemyslaw Skibinski | 5c5f01f | 2016-10-25 12:25:07 +0200 | [diff] [blame] | 354 | typedef enum { ZSTD_fast, ZSTD_dfast, ZSTD_greedy, ZSTD_lazy, ZSTD_lazy2, ZSTD_btlazy2, ZSTD_btopt, ZSTD_btopt2 } ZSTD_strategy; /* from faster to stronger */ |
Yann Collet | d3b7f8d | 2016-06-04 19:47:02 +0200 | [diff] [blame] | 355 | |
| 356 | typedef struct { |
Yann Collet | 655393c | 2016-08-14 00:16:20 +0200 | [diff] [blame] | 357 | unsigned windowLog; /**< largest match distance : larger == more compression, more memory needed during decompression */ |
| 358 | unsigned chainLog; /**< fully searched segment : larger == more compression, slower, more memory (useless for fast) */ |
| 359 | unsigned hashLog; /**< dispatch table : larger == faster, more memory */ |
| 360 | unsigned searchLog; /**< nb of searches : larger == more compression, slower */ |
| 361 | unsigned searchLength; /**< match length searched : larger == faster decompression, sometimes less compression */ |
| 362 | unsigned targetLength; /**< acceptable match size for optimal parser (only) : larger == more compression, slower */ |
Yann Collet | d3b7f8d | 2016-06-04 19:47:02 +0200 | [diff] [blame] | 363 | ZSTD_strategy strategy; |
| 364 | } ZSTD_compressionParameters; |
| 365 | |
| 366 | typedef struct { |
Yann Collet | 655393c | 2016-08-14 00:16:20 +0200 | [diff] [blame] | 367 | unsigned contentSizeFlag; /**< 1: content size will be in frame header (if known). */ |
| 368 | unsigned checksumFlag; /**< 1: will generate a 22-bits checksum at end of frame, to be used for error detection by decompressor */ |
| 369 | unsigned noDictIDFlag; /**< 1: no dict ID will be saved into frame header (if dictionary compression) */ |
Yann Collet | d3b7f8d | 2016-06-04 19:47:02 +0200 | [diff] [blame] | 370 | } ZSTD_frameParameters; |
| 371 | |
| 372 | typedef struct { |
| 373 | ZSTD_compressionParameters cParams; |
| 374 | ZSTD_frameParameters fParams; |
| 375 | } ZSTD_parameters; |
| 376 | |
inikep | 82057aa | 2016-10-06 13:23:52 +0200 | [diff] [blame] | 377 | /*= Custom memory allocation functions */ |
Yann Collet | d3b7f8d | 2016-06-04 19:47:02 +0200 | [diff] [blame] | 378 | typedef void* (*ZSTD_allocFunction) (void* opaque, size_t size); |
| 379 | typedef void (*ZSTD_freeFunction) (void* opaque, void* address); |
| 380 | typedef struct { ZSTD_allocFunction customAlloc; ZSTD_freeFunction customFree; void* opaque; } ZSTD_customMem; |
| 381 | |
| 382 | |
inikep | 82057aa | 2016-10-06 13:23:52 +0200 | [diff] [blame] | 383 | /*************************************** |
Yann Collet | 81e13ef | 2016-06-07 00:51:51 +0200 | [diff] [blame] | 384 | * Advanced compression functions |
Yann Collet | d3b7f8d | 2016-06-04 19:47:02 +0200 | [diff] [blame] | 385 | ***************************************/ |
Yann Collet | 3ae543c | 2016-07-11 03:12:17 +0200 | [diff] [blame] | 386 | /*! ZSTD_estimateCCtxSize() : |
| 387 | * Gives the amount of memory allocated for a ZSTD_CCtx given a set of compression parameters. |
| 388 | * `frameContentSize` is an optional parameter, provide `0` if unknown */ |
Yann Collet | 8847238 | 2016-07-14 17:05:38 +0200 | [diff] [blame] | 389 | ZSTDLIB_API size_t ZSTD_estimateCCtxSize(ZSTD_compressionParameters cParams); |
Yann Collet | 3ae543c | 2016-07-11 03:12:17 +0200 | [diff] [blame] | 390 | |
Yann Collet | d3b7f8d | 2016-06-04 19:47:02 +0200 | [diff] [blame] | 391 | /*! ZSTD_createCCtx_advanced() : |
| 392 | * Create a ZSTD compression context using external alloc and free functions */ |
| 393 | ZSTDLIB_API ZSTD_CCtx* ZSTD_createCCtx_advanced(ZSTD_customMem customMem); |
| 394 | |
Yann Collet | d7c6589 | 2016-09-15 02:50:27 +0200 | [diff] [blame] | 395 | /*! ZSTD_sizeofCCtx() : |
| 396 | * Gives the amount of memory used by a given ZSTD_CCtx */ |
| 397 | ZSTDLIB_API size_t ZSTD_sizeof_CCtx(const ZSTD_CCtx* cctx); |
| 398 | |
Yann Collet | 81e13ef | 2016-06-07 00:51:51 +0200 | [diff] [blame] | 399 | /*! ZSTD_createCDict_advanced() : |
| 400 | * Create a ZSTD_CDict using external alloc and free, and customized compression parameters */ |
| 401 | ZSTDLIB_API ZSTD_CDict* ZSTD_createCDict_advanced(const void* dict, size_t dictSize, |
| 402 | ZSTD_parameters params, ZSTD_customMem customMem); |
Yann Collet | d3b7f8d | 2016-06-04 19:47:02 +0200 | [diff] [blame] | 403 | |
Yann Collet | d7c6589 | 2016-09-15 02:50:27 +0200 | [diff] [blame] | 404 | /*! ZSTD_sizeof_CDict() : |
| 405 | * Gives the amount of memory used by a given ZSTD_sizeof_CDict */ |
| 406 | ZSTDLIB_API size_t ZSTD_sizeof_CDict(const ZSTD_CDict* cdict); |
Yann Collet | 8e0ee68 | 2016-07-11 13:09:52 +0200 | [diff] [blame] | 407 | |
Yann Collet | 6c6e175 | 2016-06-27 15:28:45 +0200 | [diff] [blame] | 408 | /*! ZSTD_getParams() : |
| 409 | * same as ZSTD_getCParams(), but @return a full `ZSTD_parameters` object instead of a `ZSTD_compressionParameters`. |
| 410 | * All fields of `ZSTD_frameParameters` are set to default (0) */ |
Yann Collet | 70e3b31 | 2016-08-23 01:18:06 +0200 | [diff] [blame] | 411 | ZSTDLIB_API ZSTD_parameters ZSTD_getParams(int compressionLevel, unsigned long long srcSize, size_t dictSize); |
Yann Collet | 6c6e175 | 2016-06-27 15:28:45 +0200 | [diff] [blame] | 412 | |
Yann Collet | d3b7f8d | 2016-06-04 19:47:02 +0200 | [diff] [blame] | 413 | /*! ZSTD_getCParams() : |
| 414 | * @return ZSTD_compressionParameters structure for a selected compression level and srcSize. |
| 415 | * `srcSize` value is optional, select 0 if not known */ |
Yann Collet | 52c04fe | 2016-07-07 11:53:18 +0200 | [diff] [blame] | 416 | ZSTDLIB_API ZSTD_compressionParameters ZSTD_getCParams(int compressionLevel, unsigned long long srcSize, size_t dictSize); |
Yann Collet | d3b7f8d | 2016-06-04 19:47:02 +0200 | [diff] [blame] | 417 | |
Yann Collet | 3d2cd7f | 2016-06-27 15:12:26 +0200 | [diff] [blame] | 418 | /*! ZSTD_checkCParams() : |
Yann Collet | d3b7f8d | 2016-06-04 19:47:02 +0200 | [diff] [blame] | 419 | * Ensure param values remain within authorized range */ |
| 420 | ZSTDLIB_API size_t ZSTD_checkCParams(ZSTD_compressionParameters params); |
| 421 | |
Yann Collet | 3d2cd7f | 2016-06-27 15:12:26 +0200 | [diff] [blame] | 422 | /*! ZSTD_adjustCParams() : |
Yann Collet | d3b7f8d | 2016-06-04 19:47:02 +0200 | [diff] [blame] | 423 | * optimize params for a given `srcSize` and `dictSize`. |
| 424 | * both values are optional, select `0` if unknown. */ |
Yann Collet | 52c04fe | 2016-07-07 11:53:18 +0200 | [diff] [blame] | 425 | ZSTDLIB_API ZSTD_compressionParameters ZSTD_adjustCParams(ZSTD_compressionParameters cPar, unsigned long long srcSize, size_t dictSize); |
Yann Collet | d3b7f8d | 2016-06-04 19:47:02 +0200 | [diff] [blame] | 426 | |
| 427 | /*! ZSTD_compress_advanced() : |
| 428 | * Same as ZSTD_compress_usingDict(), with fine-tune control of each compression parameter */ |
| 429 | ZSTDLIB_API size_t ZSTD_compress_advanced (ZSTD_CCtx* ctx, |
| 430 | void* dst, size_t dstCapacity, |
| 431 | const void* src, size_t srcSize, |
| 432 | const void* dict,size_t dictSize, |
| 433 | ZSTD_parameters params); |
| 434 | |
Yann Collet | 45c03c5 | 2016-06-14 13:46:11 +0200 | [diff] [blame] | 435 | |
Przemyslaw Skibinski | 984b66c | 2016-10-24 15:59:51 +0200 | [diff] [blame] | 436 | /*--- Advanced decompression functions ---*/ |
Yann Collet | d3b7f8d | 2016-06-04 19:47:02 +0200 | [diff] [blame] | 437 | |
Yann Collet | d158c35 | 2016-07-11 13:46:25 +0200 | [diff] [blame] | 438 | /*! ZSTD_estimateDCtxSize() : |
| 439 | * Gives the potential amount of memory allocated to create a ZSTD_DCtx */ |
| 440 | ZSTDLIB_API size_t ZSTD_estimateDCtxSize(void); |
| 441 | |
Yann Collet | 81e13ef | 2016-06-07 00:51:51 +0200 | [diff] [blame] | 442 | /*! ZSTD_createDCtx_advanced() : |
| 443 | * Create a ZSTD decompression context using external alloc and free functions */ |
| 444 | ZSTDLIB_API ZSTD_DCtx* ZSTD_createDCtx_advanced(ZSTD_customMem customMem); |
Yann Collet | d3b7f8d | 2016-06-04 19:47:02 +0200 | [diff] [blame] | 445 | |
Yann Collet | d7c6589 | 2016-09-15 02:50:27 +0200 | [diff] [blame] | 446 | /*! ZSTD_sizeof_DCtx() : |
Yann Collet | d158c35 | 2016-07-11 13:46:25 +0200 | [diff] [blame] | 447 | * Gives the amount of memory used by a given ZSTD_DCtx */ |
Yann Collet | 70e3b31 | 2016-08-23 01:18:06 +0200 | [diff] [blame] | 448 | ZSTDLIB_API size_t ZSTD_sizeof_DCtx(const ZSTD_DCtx* dctx); |
Yann Collet | 8e0ee68 | 2016-07-11 13:09:52 +0200 | [diff] [blame] | 449 | |
Yann Collet | e91c4b4 | 2016-09-14 16:55:44 +0200 | [diff] [blame] | 450 | /*! ZSTD_sizeof_DDict() : |
| 451 | * Gives the amount of memory used by a given ZSTD_DDict */ |
| 452 | ZSTDLIB_API size_t ZSTD_sizeof_DDict(const ZSTD_DDict* ddict); |
| 453 | |
Yann Collet | d3b7f8d | 2016-06-04 19:47:02 +0200 | [diff] [blame] | 454 | |
inikep | 82057aa | 2016-10-06 13:23:52 +0200 | [diff] [blame] | 455 | /******************************************************************** |
Przemyslaw Skibinski | 984b66c | 2016-10-24 15:59:51 +0200 | [diff] [blame] | 456 | * Advanced streaming functions |
Yann Collet | 5a0c8e2 | 2016-08-12 01:20:36 +0200 | [diff] [blame] | 457 | ********************************************************************/ |
| 458 | |
inikep | 82057aa | 2016-10-06 13:23:52 +0200 | [diff] [blame] | 459 | /*===== Advanced Streaming compression functions =====*/ |
Yann Collet | 70e3b31 | 2016-08-23 01:18:06 +0200 | [diff] [blame] | 460 | ZSTDLIB_API ZSTD_CStream* ZSTD_createCStream_advanced(ZSTD_customMem customMem); |
| 461 | ZSTDLIB_API size_t ZSTD_initCStream_usingDict(ZSTD_CStream* zcs, const void* dict, size_t dictSize, int compressionLevel); |
| 462 | ZSTDLIB_API size_t ZSTD_initCStream_advanced(ZSTD_CStream* zcs, const void* dict, size_t dictSize, |
Yann Collet | 4cb2129 | 2016-09-15 14:54:07 +0200 | [diff] [blame] | 463 | ZSTD_parameters params, unsigned long long pledgedSrcSize); /**< pledgedSrcSize is optional and can be zero == unknown */ |
Yann Collet | 9516234 | 2016-10-25 16:19:52 -0700 | [diff] [blame] | 464 | ZSTDLIB_API size_t ZSTD_initCStream_usingCDict(ZSTD_CStream* zcs, const ZSTD_CDict* cdict); /**< note : cdict will just be referenced, and must outlive compression session */ |
Yann Collet | ee5b725 | 2016-10-27 14:20:55 -0700 | [diff] [blame] | 465 | ZSTDLIB_API size_t ZSTD_resetCStream(ZSTD_CStream* zcs, unsigned long long pledgedSrcSize); /**< re-use compression parameters from previous init; skip dictionary loading stage; zcs must be init at least once before */ |
Yann Collet | 70e3b31 | 2016-08-23 01:18:06 +0200 | [diff] [blame] | 466 | ZSTDLIB_API size_t ZSTD_sizeof_CStream(const ZSTD_CStream* zcs); |
Yann Collet | cb32763 | 2016-08-23 00:30:31 +0200 | [diff] [blame] | 467 | |
Yann Collet | 5a0c8e2 | 2016-08-12 01:20:36 +0200 | [diff] [blame] | 468 | |
inikep | 82057aa | 2016-10-06 13:23:52 +0200 | [diff] [blame] | 469 | /*===== Advanced Streaming decompression functions =====*/ |
Yann Collet | 17e482e | 2016-08-23 16:58:10 +0200 | [diff] [blame] | 470 | typedef enum { ZSTDdsp_maxWindowSize } ZSTD_DStreamParameter_e; |
Yann Collet | 70e3b31 | 2016-08-23 01:18:06 +0200 | [diff] [blame] | 471 | ZSTDLIB_API ZSTD_DStream* ZSTD_createDStream_advanced(ZSTD_customMem customMem); |
| 472 | ZSTDLIB_API size_t ZSTD_initDStream_usingDict(ZSTD_DStream* zds, const void* dict, size_t dictSize); |
Yann Collet | 17e482e | 2016-08-23 16:58:10 +0200 | [diff] [blame] | 473 | ZSTDLIB_API size_t ZSTD_setDStreamParameter(ZSTD_DStream* zds, ZSTD_DStreamParameter_e paramType, unsigned paramValue); |
Yann Collet | 9516234 | 2016-10-25 16:19:52 -0700 | [diff] [blame] | 474 | ZSTDLIB_API size_t ZSTD_initDStream_usingDDict(ZSTD_DStream* zds, const ZSTD_DDict* ddict); /**< note : ddict will just be referenced, and must outlive decompression session */ |
Yann Collet | 4cb2129 | 2016-09-15 14:54:07 +0200 | [diff] [blame] | 475 | ZSTDLIB_API size_t ZSTD_resetDStream(ZSTD_DStream* zds); /**< re-use decompression parameters from previous init; saves dictionary loading */ |
Yann Collet | 70e3b31 | 2016-08-23 01:18:06 +0200 | [diff] [blame] | 476 | ZSTDLIB_API size_t ZSTD_sizeof_DStream(const ZSTD_DStream* zds); |
Yann Collet | 5a0c8e2 | 2016-08-12 01:20:36 +0200 | [diff] [blame] | 477 | |
| 478 | |
inikep | 82057aa | 2016-10-06 13:23:52 +0200 | [diff] [blame] | 479 | /********************************************************************* |
Yann Collet | 5a0c8e2 | 2016-08-12 01:20:36 +0200 | [diff] [blame] | 480 | * Buffer-less and synchronous inner streaming functions |
inikep | 82057aa | 2016-10-06 13:23:52 +0200 | [diff] [blame] | 481 | * |
| 482 | * This is an advanced API, giving full control over buffer management, for users which need direct control over memory. |
Yann Collet | 655393c | 2016-08-14 00:16:20 +0200 | [diff] [blame] | 483 | * But it's also a complex one, with many restrictions (documented below). |
Yann Collet | 37d1300 | 2016-10-24 17:22:12 -0700 | [diff] [blame] | 484 | * Prefer using normal streaming API for an easier experience |
inikep | 82057aa | 2016-10-06 13:23:52 +0200 | [diff] [blame] | 485 | ********************************************************************* */ |
Yann Collet | 60ba31c | 2016-07-28 19:55:09 +0200 | [diff] [blame] | 486 | |
inikep | 82057aa | 2016-10-06 13:23:52 +0200 | [diff] [blame] | 487 | /** |
| 488 | Buffer-less streaming compression (synchronous mode) |
Yann Collet | d3b7f8d | 2016-06-04 19:47:02 +0200 | [diff] [blame] | 489 | |
Yann Collet | d3b7f8d | 2016-06-04 19:47:02 +0200 | [diff] [blame] | 490 | A ZSTD_CCtx object is required to track streaming operations. |
Yann Collet | 45c03c5 | 2016-06-14 13:46:11 +0200 | [diff] [blame] | 491 | Use ZSTD_createCCtx() / ZSTD_freeCCtx() to manage resource. |
Yann Collet | d3b7f8d | 2016-06-04 19:47:02 +0200 | [diff] [blame] | 492 | ZSTD_CCtx object can be re-used multiple times within successive compression operations. |
| 493 | |
| 494 | Start by initializing a context. |
| 495 | Use ZSTD_compressBegin(), or ZSTD_compressBegin_usingDict() for dictionary compression, |
| 496 | or ZSTD_compressBegin_advanced(), for finer parameter control. |
| 497 | It's also possible to duplicate a reference context which has already been initialized, using ZSTD_copyCCtx() |
| 498 | |
| 499 | Then, consume your input using ZSTD_compressContinue(). |
Yann Collet | a49e066 | 2016-06-21 11:54:03 +0200 | [diff] [blame] | 500 | There are some important considerations to keep in mind when using this advanced function : |
| 501 | - ZSTD_compressContinue() has no internal buffer. It uses externally provided buffer only. |
Yann Collet | 62470b4 | 2016-07-28 15:29:08 +0200 | [diff] [blame] | 502 | - Interface is synchronous : input is consumed entirely and produce 1+ (or more) compressed blocks. |
Yann Collet | a49e066 | 2016-06-21 11:54:03 +0200 | [diff] [blame] | 503 | - Caller must ensure there is enough space in `dst` to store compressed data under worst case scenario. |
| 504 | Worst case evaluation is provided by ZSTD_compressBound(). |
| 505 | ZSTD_compressContinue() doesn't guarantee recover after a failed compression. |
| 506 | - ZSTD_compressContinue() presumes prior input ***is still accessible and unmodified*** (up to maximum distance size, see WindowLog). |
| 507 | It remembers all previous contiguous blocks, plus one separated memory segment (which can itself consists of multiple contiguous blocks) |
| 508 | - ZSTD_compressContinue() detects that prior input has been overwritten when `src` buffer overlaps. |
| 509 | In which case, it will "discard" the relevant memory section from its history. |
| 510 | |
Yann Collet | 62470b4 | 2016-07-28 15:29:08 +0200 | [diff] [blame] | 511 | Finish a frame with ZSTD_compressEnd(), which will write the last block(s) and optional checksum. |
| 512 | It's possible to use a NULL,0 src content, in which case, it will write a final empty block to end the frame, |
| 513 | Without last block mark, frames will be considered unfinished (broken) by decoders. |
Yann Collet | d3b7f8d | 2016-06-04 19:47:02 +0200 | [diff] [blame] | 514 | |
Yann Collet | a49e066 | 2016-06-21 11:54:03 +0200 | [diff] [blame] | 515 | You can then reuse `ZSTD_CCtx` (ZSTD_compressBegin()) to compress some new frame. |
Yann Collet | d3b7f8d | 2016-06-04 19:47:02 +0200 | [diff] [blame] | 516 | */ |
| 517 | |
inikep | 82057aa | 2016-10-06 13:23:52 +0200 | [diff] [blame] | 518 | /*===== Buffer-less streaming compression functions =====*/ |
| 519 | ZSTDLIB_API size_t ZSTD_compressBegin(ZSTD_CCtx* cctx, int compressionLevel); |
| 520 | ZSTDLIB_API size_t ZSTD_compressBegin_usingDict(ZSTD_CCtx* cctx, const void* dict, size_t dictSize, int compressionLevel); |
| 521 | ZSTDLIB_API size_t ZSTD_compressBegin_advanced(ZSTD_CCtx* cctx, const void* dict, size_t dictSize, ZSTD_parameters params, unsigned long long pledgedSrcSize); |
| 522 | ZSTDLIB_API size_t ZSTD_copyCCtx(ZSTD_CCtx* cctx, const ZSTD_CCtx* preparedCCtx, unsigned long long pledgedSrcSize); |
| 523 | ZSTDLIB_API size_t ZSTD_compressContinue(ZSTD_CCtx* cctx, void* dst, size_t dstCapacity, const void* src, size_t srcSize); |
| 524 | ZSTDLIB_API size_t ZSTD_compressEnd(ZSTD_CCtx* cctx, void* dst, size_t dstCapacity, const void* src, size_t srcSize); |
Yann Collet | d3b7f8d | 2016-06-04 19:47:02 +0200 | [diff] [blame] | 525 | |
Yann Collet | d3b7f8d | 2016-06-04 19:47:02 +0200 | [diff] [blame] | 526 | |
Yann Collet | d3b7f8d | 2016-06-04 19:47:02 +0200 | [diff] [blame] | 527 | |
inikep | ba1db37 | 2016-10-06 14:22:48 +0200 | [diff] [blame] | 528 | /*- |
Yann Collet | cf05b9d | 2016-07-18 16:52:10 +0200 | [diff] [blame] | 529 | Buffer-less streaming decompression (synchronous mode) |
Yann Collet | d3b7f8d | 2016-06-04 19:47:02 +0200 | [diff] [blame] | 530 | |
| 531 | A ZSTD_DCtx object is required to track streaming operations. |
| 532 | Use ZSTD_createDCtx() / ZSTD_freeDCtx() to manage it. |
| 533 | A ZSTD_DCtx object can be re-used multiple times. |
| 534 | |
Yann Collet | 6b615d3 | 2016-07-29 19:40:37 +0200 | [diff] [blame] | 535 | First typical operation is to retrieve frame parameters, using ZSTD_getFrameParams(). |
| 536 | It fills a ZSTD_frameParams structure which provide important information to correctly decode the frame, |
| 537 | such as the minimum rolling buffer size to allocate to decompress data (`windowSize`), |
| 538 | and the dictionary ID used. |
| 539 | (Note : content size is optional, it may not be present. 0 means : content size unknown). |
| 540 | Note that these values could be wrong, either because of data malformation, or because an attacker is spoofing deliberate false information. |
| 541 | As a consequence, check that values remain within valid application range, especially `windowSize`, before allocation. |
| 542 | Each application can set its own limit, depending on local restrictions. For extended interoperability, it is recommended to support at least 8 MB. |
| 543 | Frame parameters are extracted from the beginning of the compressed frame. |
| 544 | Data fragment must be large enough to ensure successful decoding, typically `ZSTD_frameHeaderSize_max` bytes. |
| 545 | @result : 0 : successful decoding, the `ZSTD_frameParams` structure is correctly filled. |
| 546 | >0 : `srcSize` is too small, please provide at least @result bytes on next attempt. |
Yann Collet | d469a98 | 2016-07-28 03:47:45 +0200 | [diff] [blame] | 547 | errorCode, which can be tested using ZSTD_isError(). |
Yann Collet | d3b7f8d | 2016-06-04 19:47:02 +0200 | [diff] [blame] | 548 | |
| 549 | Start decompression, with ZSTD_decompressBegin() or ZSTD_decompressBegin_usingDict(). |
| 550 | Alternatively, you can copy a prepared context, using ZSTD_copyDCtx(). |
| 551 | |
| 552 | Then use ZSTD_nextSrcSizeToDecompress() and ZSTD_decompressContinue() alternatively. |
Yann Collet | 6b615d3 | 2016-07-29 19:40:37 +0200 | [diff] [blame] | 553 | ZSTD_nextSrcSizeToDecompress() tells how many bytes to provide as 'srcSize' to ZSTD_decompressContinue(). |
| 554 | ZSTD_decompressContinue() requires this _exact_ amount of bytes, or it will fail. |
Yann Collet | d3b7f8d | 2016-06-04 19:47:02 +0200 | [diff] [blame] | 555 | |
Yann Collet | 49bb004 | 2016-06-04 20:17:38 +0200 | [diff] [blame] | 556 | @result of ZSTD_decompressContinue() is the number of bytes regenerated within 'dst' (necessarily <= dstCapacity). |
Yann Collet | 6b615d3 | 2016-07-29 19:40:37 +0200 | [diff] [blame] | 557 | It can be zero, which is not an error; it just means ZSTD_decompressContinue() has decoded some metadata item. |
| 558 | It can also be an error code, which can be tested with ZSTD_isError(). |
Yann Collet | d3b7f8d | 2016-06-04 19:47:02 +0200 | [diff] [blame] | 559 | |
Yann Collet | 3b6ae77 | 2016-07-08 23:42:22 +0200 | [diff] [blame] | 560 | ZSTD_decompressContinue() needs previous data blocks during decompression, up to `windowSize`. |
| 561 | They should preferably be located contiguously, prior to current block. |
| 562 | Alternatively, a round buffer of sufficient size is also possible. Sufficient size is determined by frame parameters. |
| 563 | ZSTD_decompressContinue() is very sensitive to contiguity, |
| 564 | if 2 blocks don't follow each other, make sure that either the compressor breaks contiguity at the same place, |
Yann Collet | d469a98 | 2016-07-28 03:47:45 +0200 | [diff] [blame] | 565 | or that previous contiguous segment is large enough to properly handle maximum back-reference. |
Yann Collet | 3b6ae77 | 2016-07-08 23:42:22 +0200 | [diff] [blame] | 566 | |
Yann Collet | d3b7f8d | 2016-06-04 19:47:02 +0200 | [diff] [blame] | 567 | A frame is fully decoded when ZSTD_nextSrcSizeToDecompress() returns zero. |
| 568 | Context can then be reset to start a new decompression. |
| 569 | |
Yann Collet | 4c5bbf6 | 2016-07-28 20:30:25 +0200 | [diff] [blame] | 570 | Note : it's possible to know if next input to present is a header or a block, using ZSTD_nextInputType(). |
Yann Collet | 6b615d3 | 2016-07-29 19:40:37 +0200 | [diff] [blame] | 571 | This information is not required to properly decode a frame. |
Yann Collet | 3b6ae77 | 2016-07-08 23:42:22 +0200 | [diff] [blame] | 572 | |
| 573 | == Special case : skippable frames == |
| 574 | |
Yann Collet | d469a98 | 2016-07-28 03:47:45 +0200 | [diff] [blame] | 575 | Skippable frames allow integration of user-defined data into a flow of concatenated frames. |
Yann Collet | 5b56739 | 2016-07-28 01:17:22 +0200 | [diff] [blame] | 576 | Skippable frames will be ignored (skipped) by a decompressor. The format of skippable frames is as follows : |
Yann Collet | d3b7f8d | 2016-06-04 19:47:02 +0200 | [diff] [blame] | 577 | a) Skippable frame ID - 4 Bytes, Little endian format, any value from 0x184D2A50 to 0x184D2A5F |
| 578 | b) Frame Size - 4 Bytes, Little endian format, unsigned 32-bits |
| 579 | c) Frame Content - any content (User Data) of length equal to Frame Size |
| 580 | For skippable frames ZSTD_decompressContinue() always returns 0. |
| 581 | For skippable frames ZSTD_getFrameParams() returns fparamsPtr->windowLog==0 what means that a frame is skippable. |
| 582 | It also returns Frame Size as fparamsPtr->frameContentSize. |
| 583 | */ |
| 584 | |
inikep | 82057aa | 2016-10-06 13:23:52 +0200 | [diff] [blame] | 585 | typedef struct { |
| 586 | unsigned long long frameContentSize; |
| 587 | unsigned windowSize; |
| 588 | unsigned dictID; |
| 589 | unsigned checksumFlag; |
| 590 | } ZSTD_frameParams; |
Yann Collet | d3b7f8d | 2016-06-04 19:47:02 +0200 | [diff] [blame] | 591 | |
inikep | 82057aa | 2016-10-06 13:23:52 +0200 | [diff] [blame] | 592 | /*===== Buffer-less streaming decompression functions =====*/ |
| 593 | ZSTDLIB_API size_t ZSTD_getFrameParams(ZSTD_frameParams* fparamsPtr, const void* src, size_t srcSize); /**< doesn't consume input, see details below */ |
| 594 | ZSTDLIB_API size_t ZSTD_decompressBegin(ZSTD_DCtx* dctx); |
| 595 | ZSTDLIB_API size_t ZSTD_decompressBegin_usingDict(ZSTD_DCtx* dctx, const void* dict, size_t dictSize); |
| 596 | ZSTDLIB_API void ZSTD_copyDCtx(ZSTD_DCtx* dctx, const ZSTD_DCtx* preparedDCtx); |
| 597 | ZSTDLIB_API size_t ZSTD_nextSrcSizeToDecompress(ZSTD_DCtx* dctx); |
| 598 | ZSTDLIB_API size_t ZSTD_decompressContinue(ZSTD_DCtx* dctx, void* dst, size_t dstCapacity, const void* src, size_t srcSize); |
| 599 | typedef enum { ZSTDnit_frameHeader, ZSTDnit_blockHeader, ZSTDnit_block, ZSTDnit_lastBlock, ZSTDnit_checksum, ZSTDnit_skippableFrame } ZSTD_nextInputType_e; |
| 600 | ZSTDLIB_API ZSTD_nextInputType_e ZSTD_nextInputType(ZSTD_DCtx* dctx); |
| 601 | |
| 602 | /** |
| 603 | Block functions |
| 604 | |
| 605 | Block functions produce and decode raw zstd blocks, without frame metadata. |
Yann Collet | cf05b9d | 2016-07-18 16:52:10 +0200 | [diff] [blame] | 606 | Frame metadata cost is typically ~18 bytes, which can be non-negligible for very small blocks (< 100 bytes). |
Yann Collet | d3b7f8d | 2016-06-04 19:47:02 +0200 | [diff] [blame] | 607 | User will have to take in charge required information to regenerate data, such as compressed and content sizes. |
| 608 | |
| 609 | A few rules to respect : |
Yann Collet | f246cf5 | 2016-07-06 20:30:52 +0200 | [diff] [blame] | 610 | - Compressing and decompressing require a context structure |
Yann Collet | d3b7f8d | 2016-06-04 19:47:02 +0200 | [diff] [blame] | 611 | + Use ZSTD_createCCtx() and ZSTD_createDCtx() |
| 612 | - It is necessary to init context before starting |
| 613 | + compression : ZSTD_compressBegin() |
| 614 | + decompression : ZSTD_decompressBegin() |
| 615 | + variants _usingDict() are also allowed |
| 616 | + copyCCtx() and copyDCtx() work too |
Yann Collet | cf05b9d | 2016-07-18 16:52:10 +0200 | [diff] [blame] | 617 | - Block size is limited, it must be <= ZSTD_getBlockSizeMax() |
| 618 | + If you need to compress more, cut data into multiple blocks |
| 619 | + Consider using the regular ZSTD_compress() instead, as frame metadata costs become negligible when source size is large. |
Yann Collet | d3b7f8d | 2016-06-04 19:47:02 +0200 | [diff] [blame] | 620 | - When a block is considered not compressible enough, ZSTD_compressBlock() result will be zero. |
| 621 | In which case, nothing is produced into `dst`. |
| 622 | + User must test for such outcome and deal directly with uncompressed data |
Yann Collet | f246cf5 | 2016-07-06 20:30:52 +0200 | [diff] [blame] | 623 | + ZSTD_decompressBlock() doesn't accept uncompressed data as input !!! |
| 624 | + In case of multiple successive blocks, decoder must be informed of uncompressed block existence to follow proper history. |
| 625 | Use ZSTD_insertBlock() in such a case. |
Yann Collet | d3b7f8d | 2016-06-04 19:47:02 +0200 | [diff] [blame] | 626 | */ |
| 627 | |
Yann Collet | cf05b9d | 2016-07-18 16:52:10 +0200 | [diff] [blame] | 628 | #define ZSTD_BLOCKSIZE_ABSOLUTEMAX (128 * 1024) /* define, for static allocation */ |
inikep | 82057aa | 2016-10-06 13:23:52 +0200 | [diff] [blame] | 629 | /*===== Raw zstd block functions =====*/ |
Yann Collet | cf05b9d | 2016-07-18 16:52:10 +0200 | [diff] [blame] | 630 | ZSTDLIB_API size_t ZSTD_getBlockSizeMax(ZSTD_CCtx* cctx); |
Yann Collet | d3b7f8d | 2016-06-04 19:47:02 +0200 | [diff] [blame] | 631 | ZSTDLIB_API size_t ZSTD_compressBlock (ZSTD_CCtx* cctx, void* dst, size_t dstCapacity, const void* src, size_t srcSize); |
| 632 | ZSTDLIB_API size_t ZSTD_decompressBlock(ZSTD_DCtx* dctx, void* dst, size_t dstCapacity, const void* src, size_t srcSize); |
Yann Collet | d5c5a77 | 2016-07-19 15:06:55 +0200 | [diff] [blame] | 633 | ZSTDLIB_API size_t ZSTD_insertBlock(ZSTD_DCtx* dctx, const void* blockStart, size_t blockSize); /**< insert block into `dctx` history. Useful for uncompressed blocks */ |
Yann Collet | d3b7f8d | 2016-06-04 19:47:02 +0200 | [diff] [blame] | 634 | |
| 635 | |
Yann Collet | d3b7f8d | 2016-06-04 19:47:02 +0200 | [diff] [blame] | 636 | #endif /* ZSTD_STATIC_LINKING_ONLY */ |
| 637 | |
Yann Collet | 4856a00 | 2015-01-24 01:58:16 +0100 | [diff] [blame] | 638 | #if defined (__cplusplus) |
| 639 | } |
| 640 | #endif |
Yann Collet | aa07405 | 2015-10-30 11:21:50 +0100 | [diff] [blame] | 641 | |
Yann Collet | d3b7f8d | 2016-06-04 19:47:02 +0200 | [diff] [blame] | 642 | #endif /* ZSTD_H_235446 */ |