5 * This source code is licensed under the BSD-style license found in the |
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 |
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. |
7 * of patent rights can be found in the PATENTS file in the same directory. |
8 */ |
8 */ |
9 |
9 |
10 #ifndef ZSTD_H_235446 |
|
11 #define ZSTD_H_235446 |
|
12 |
|
13 #if defined (__cplusplus) |
10 #if defined (__cplusplus) |
14 extern "C" { |
11 extern "C" { |
15 #endif |
12 #endif |
16 |
13 |
|
14 #ifndef ZSTD_H_235446 |
|
15 #define ZSTD_H_235446 |
|
16 |
17 /* ====== Dependency ======*/ |
17 /* ====== Dependency ======*/ |
18 #include <stddef.h> /* size_t */ |
18 #include <stddef.h> /* size_t */ |
19 |
19 |
20 |
20 |
21 /* ====== Export for Windows ======*/ |
21 /* ===== ZSTDLIB_API : control library symbols visibility ===== */ |
22 /* |
22 #if defined(__GNUC__) && (__GNUC__ >= 4) |
23 * ZSTD_DLL_EXPORT : |
23 # define ZSTDLIB_API __attribute__ ((visibility ("default"))) |
24 * Enable exporting of functions when building a Windows DLL |
24 #elif defined(ZSTD_DLL_EXPORT) && (ZSTD_DLL_EXPORT==1) |
25 */ |
|
26 #if defined(_WIN32) && defined(ZSTD_DLL_EXPORT) && (ZSTD_DLL_EXPORT==1) |
|
27 # define ZSTDLIB_API __declspec(dllexport) |
25 # define ZSTDLIB_API __declspec(dllexport) |
|
26 #elif defined(ZSTD_DLL_IMPORT) && (ZSTD_DLL_IMPORT==1) |
|
27 # define ZSTDLIB_API __declspec(dllimport) /* It isn't required but allows to generate better code, saving a function pointer load from the IAT and an indirect jump.*/ |
28 #else |
28 #else |
29 # define ZSTDLIB_API |
29 # define ZSTDLIB_API |
30 #endif |
30 #endif |
31 |
31 |
32 |
32 |
49 These APIs shall never be used with a dynamic library. |
49 These APIs shall never be used with a dynamic library. |
50 They are not "stable", their definition may change in the future. Only static linking is allowed. |
50 They are not "stable", their definition may change in the future. Only static linking is allowed. |
51 *********************************************************************************************************/ |
51 *********************************************************************************************************/ |
52 |
52 |
53 /*------ Version ------*/ |
53 /*------ Version ------*/ |
54 ZSTDLIB_API unsigned ZSTD_versionNumber (void); /**< returns version number of ZSTD */ |
|
55 |
|
56 #define ZSTD_VERSION_MAJOR 1 |
54 #define ZSTD_VERSION_MAJOR 1 |
57 #define ZSTD_VERSION_MINOR 1 |
55 #define ZSTD_VERSION_MINOR 1 |
58 #define ZSTD_VERSION_RELEASE 1 |
56 #define ZSTD_VERSION_RELEASE 2 |
59 |
57 |
60 #define ZSTD_LIB_VERSION ZSTD_VERSION_MAJOR.ZSTD_VERSION_MINOR.ZSTD_VERSION_RELEASE |
58 #define ZSTD_LIB_VERSION ZSTD_VERSION_MAJOR.ZSTD_VERSION_MINOR.ZSTD_VERSION_RELEASE |
61 #define ZSTD_QUOTE(str) #str |
59 #define ZSTD_QUOTE(str) #str |
62 #define ZSTD_EXPAND_AND_QUOTE(str) ZSTD_QUOTE(str) |
60 #define ZSTD_EXPAND_AND_QUOTE(str) ZSTD_QUOTE(str) |
63 #define ZSTD_VERSION_STRING ZSTD_EXPAND_AND_QUOTE(ZSTD_LIB_VERSION) |
61 #define ZSTD_VERSION_STRING ZSTD_EXPAND_AND_QUOTE(ZSTD_LIB_VERSION) |
64 |
62 |
65 #define ZSTD_VERSION_NUMBER (ZSTD_VERSION_MAJOR *100*100 + ZSTD_VERSION_MINOR *100 + ZSTD_VERSION_RELEASE) |
63 #define ZSTD_VERSION_NUMBER (ZSTD_VERSION_MAJOR *100*100 + ZSTD_VERSION_MINOR *100 + ZSTD_VERSION_RELEASE) |
|
64 ZSTDLIB_API unsigned ZSTD_versionNumber(void); /**< library version number; to be used when checking dll version */ |
66 |
65 |
67 |
66 |
68 /*************************************** |
67 /*************************************** |
69 * Simple API |
68 * Simple API |
70 ***************************************/ |
69 ***************************************/ |
71 /*! ZSTD_compress() : |
70 /*! ZSTD_compress() : |
72 Compresses `src` content as a single zstd compressed frame into already allocated `dst`. |
71 Compresses `src` content as a single zstd compressed frame into already allocated `dst`. |
73 Hint : compression runs faster if `dstCapacity` >= `ZSTD_compressBound(srcSize)`. |
72 Hint : compression runs faster if `dstCapacity` >= `ZSTD_compressBound(srcSize)`. |
74 @return : compressed size written into `dst` (<= `dstCapacity), |
73 @return : compressed size written into `dst` (<= `dstCapacity), |
75 or an error code if it fails (which can be tested using ZSTD_isError()) */ |
74 or an error code if it fails (which can be tested using ZSTD_isError()). */ |
76 ZSTDLIB_API size_t ZSTD_compress( void* dst, size_t dstCapacity, |
75 ZSTDLIB_API size_t ZSTD_compress( void* dst, size_t dstCapacity, |
77 const void* src, size_t srcSize, |
76 const void* src, size_t srcSize, |
78 int compressionLevel); |
77 int compressionLevel); |
79 |
78 |
80 /*! ZSTD_decompress() : |
79 /*! ZSTD_decompress() : |
81 `compressedSize` : must be the _exact_ size of a single compressed frame. |
80 `compressedSize` : must be the _exact_ size of a single compressed frame. |
82 `dstCapacity` is an upper bound of originalSize. |
81 `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. |
82 If user cannot imply a maximum upper bound, it's better to use streaming mode to decompress data. |
84 @return : the number of bytes decompressed into `dst` (<= `dstCapacity`), |
83 @return : the number of bytes decompressed into `dst` (<= `dstCapacity`), |
85 or an errorCode if it fails (which can be tested using ZSTD_isError()) */ |
84 or an errorCode if it fails (which can be tested using ZSTD_isError()). */ |
86 ZSTDLIB_API size_t ZSTD_decompress( void* dst, size_t dstCapacity, |
85 ZSTDLIB_API size_t ZSTD_decompress( void* dst, size_t dstCapacity, |
87 const void* src, size_t compressedSize); |
86 const void* src, size_t compressedSize); |
88 |
87 |
89 /*! ZSTD_getDecompressedSize() : |
88 /*! ZSTD_getDecompressedSize() : |
90 * 'src' is the start of a zstd compressed frame. |
89 * 'src' is the start of a zstd compressed frame. |
114 |
113 |
115 /*************************************** |
114 /*************************************** |
116 * Explicit memory management |
115 * Explicit memory management |
117 ***************************************/ |
116 ***************************************/ |
118 /*= Compression context |
117 /*= Compression context |
119 * When compressing many messages / blocks, |
118 * When compressing many times, |
120 * it is recommended to allocate a context just once, and re-use it for each successive compression operation. |
119 * 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. |
120 * This will make workload friendlier for system's memory. |
122 * Use one context per thread for parallel execution in multi-threaded environments. */ |
121 * Use one context per thread for parallel execution in multi-threaded environments. */ |
123 typedef struct ZSTD_CCtx_s ZSTD_CCtx; |
122 typedef struct ZSTD_CCtx_s ZSTD_CCtx; |
124 ZSTDLIB_API ZSTD_CCtx* ZSTD_createCCtx(void); |
123 ZSTDLIB_API ZSTD_CCtx* ZSTD_createCCtx(void); |
125 ZSTDLIB_API size_t ZSTD_freeCCtx(ZSTD_CCtx* cctx); |
124 ZSTDLIB_API size_t ZSTD_freeCCtx(ZSTD_CCtx* cctx); |
126 |
125 |
127 /*! ZSTD_compressCCtx() : |
126 /*! ZSTD_compressCCtx() : |
128 Same as ZSTD_compress(), requires an allocated ZSTD_CCtx (see ZSTD_createCCtx()) */ |
127 Same as ZSTD_compress(), requires an allocated ZSTD_CCtx (see ZSTD_createCCtx()). */ |
129 ZSTDLIB_API size_t ZSTD_compressCCtx(ZSTD_CCtx* ctx, void* dst, size_t dstCapacity, const void* src, size_t srcSize, int compressionLevel); |
128 ZSTDLIB_API size_t ZSTD_compressCCtx(ZSTD_CCtx* ctx, void* dst, size_t dstCapacity, const void* src, size_t srcSize, int compressionLevel); |
130 |
129 |
131 /*= Decompression context */ |
130 /*= Decompression context */ |
132 typedef struct ZSTD_DCtx_s ZSTD_DCtx; |
131 typedef struct ZSTD_DCtx_s ZSTD_DCtx; |
133 ZSTDLIB_API ZSTD_DCtx* ZSTD_createDCtx(void); |
132 ZSTDLIB_API ZSTD_DCtx* ZSTD_createDCtx(void); |
134 ZSTDLIB_API size_t ZSTD_freeDCtx(ZSTD_DCtx* dctx); |
133 ZSTDLIB_API size_t ZSTD_freeDCtx(ZSTD_DCtx* dctx); |
135 |
134 |
136 /*! ZSTD_decompressDCtx() : |
135 /*! ZSTD_decompressDCtx() : |
137 * Same as ZSTD_decompress(), requires an allocated ZSTD_DCtx (see ZSTD_createDCtx()) */ |
136 * Same as ZSTD_decompress(), requires an allocated ZSTD_DCtx (see ZSTD_createDCtx()). */ |
138 ZSTDLIB_API size_t ZSTD_decompressDCtx(ZSTD_DCtx* ctx, void* dst, size_t dstCapacity, const void* src, size_t srcSize); |
137 ZSTDLIB_API size_t ZSTD_decompressDCtx(ZSTD_DCtx* ctx, void* dst, size_t dstCapacity, const void* src, size_t srcSize); |
139 |
138 |
140 |
139 |
141 /************************** |
140 /************************** |
142 * Simple dictionary API |
141 * Simple dictionary API |
143 ***************************/ |
142 ***************************/ |
144 /*! ZSTD_compress_usingDict() : |
143 /*! ZSTD_compress_usingDict() : |
145 * Compression using a predefined Dictionary (see dictBuilder/zdict.h). |
144 * Compression using a predefined Dictionary (see dictBuilder/zdict.h). |
146 * Note : This function load the dictionary, resulting in significant startup delay. */ |
145 * Note : This function loads the dictionary, resulting in significant startup delay. |
|
146 * Note : When `dict == NULL || dictSize < 8` no dictionary is used. */ |
147 ZSTDLIB_API size_t ZSTD_compress_usingDict(ZSTD_CCtx* ctx, |
147 ZSTDLIB_API size_t ZSTD_compress_usingDict(ZSTD_CCtx* ctx, |
148 void* dst, size_t dstCapacity, |
148 void* dst, size_t dstCapacity, |
149 const void* src, size_t srcSize, |
149 const void* src, size_t srcSize, |
150 const void* dict,size_t dictSize, |
150 const void* dict,size_t dictSize, |
151 int compressionLevel); |
151 int compressionLevel); |
152 |
152 |
153 /*! ZSTD_decompress_usingDict() : |
153 /*! ZSTD_decompress_usingDict() : |
154 * Decompression using a predefined Dictionary (see dictBuilder/zdict.h). |
154 * Decompression using a predefined Dictionary (see dictBuilder/zdict.h). |
155 * Dictionary must be identical to the one used during compression. |
155 * Dictionary must be identical to the one used during compression. |
156 * Note : This function load the dictionary, resulting in significant startup delay */ |
156 * Note : This function loads the dictionary, resulting in significant startup delay. |
|
157 * Note : When `dict == NULL || dictSize < 8` no dictionary is used. */ |
157 ZSTDLIB_API size_t ZSTD_decompress_usingDict(ZSTD_DCtx* dctx, |
158 ZSTDLIB_API size_t ZSTD_decompress_usingDict(ZSTD_DCtx* dctx, |
158 void* dst, size_t dstCapacity, |
159 void* dst, size_t dstCapacity, |
159 const void* src, size_t srcSize, |
160 const void* src, size_t srcSize, |
160 const void* dict,size_t dictSize); |
161 const void* dict,size_t dictSize); |
161 |
162 |
167 |
168 |
168 /*! ZSTD_createCDict() : |
169 /*! ZSTD_createCDict() : |
169 * When compressing multiple messages / blocks with the same dictionary, it's recommended to load it just once. |
170 * When compressing multiple messages / blocks with the same dictionary, it's recommended to load it just once. |
170 * ZSTD_createCDict() will create a digested dictionary, ready to start future compression operations without startup delay. |
171 * ZSTD_createCDict() will create a digested dictionary, ready to start future compression operations without startup delay. |
171 * ZSTD_CDict can be created once and used by multiple threads concurrently, as its usage is read-only. |
172 * ZSTD_CDict can be created once and used by multiple threads concurrently, as its usage is read-only. |
172 * `dict` can be released after ZSTD_CDict creation */ |
173 * `dict` can be released after ZSTD_CDict creation. */ |
173 ZSTDLIB_API ZSTD_CDict* ZSTD_createCDict(const void* dict, size_t dictSize, int compressionLevel); |
174 ZSTDLIB_API ZSTD_CDict* ZSTD_createCDict(const void* dict, size_t dictSize, int compressionLevel); |
174 |
175 |
175 /*! ZSTD_freeCDict() : |
176 /*! ZSTD_freeCDict() : |
176 * Function frees memory allocated by ZSTD_createCDict() */ |
177 * Function frees memory allocated by ZSTD_createCDict(). */ |
177 ZSTDLIB_API size_t ZSTD_freeCDict(ZSTD_CDict* CDict); |
178 ZSTDLIB_API size_t ZSTD_freeCDict(ZSTD_CDict* CDict); |
178 |
179 |
179 /*! ZSTD_compress_usingCDict() : |
180 /*! ZSTD_compress_usingCDict() : |
180 * Compression using a digested Dictionary. |
181 * Compression using a digested Dictionary. |
181 * Faster startup than ZSTD_compress_usingDict(), recommended when same dictionary is used multiple times. |
182 * Faster startup than ZSTD_compress_usingDict(), recommended when same dictionary is used multiple times. |
182 * Note that compression level is decided during dictionary creation */ |
183 * Note that compression level is decided during dictionary creation. */ |
183 ZSTDLIB_API size_t ZSTD_compress_usingCDict(ZSTD_CCtx* cctx, |
184 ZSTDLIB_API size_t ZSTD_compress_usingCDict(ZSTD_CCtx* cctx, |
184 void* dst, size_t dstCapacity, |
185 void* dst, size_t dstCapacity, |
185 const void* src, size_t srcSize, |
186 const void* src, size_t srcSize, |
186 const ZSTD_CDict* cdict); |
187 const ZSTD_CDict* cdict); |
187 |
188 |
188 |
189 |
189 typedef struct ZSTD_DDict_s ZSTD_DDict; |
190 typedef struct ZSTD_DDict_s ZSTD_DDict; |
190 |
191 |
191 /*! ZSTD_createDDict() : |
192 /*! ZSTD_createDDict() : |
192 * Create a digested dictionary, ready to start decompression operation without startup delay. |
193 * Create a digested dictionary, ready to start decompression operation without startup delay. |
193 * `dict` can be released after creation */ |
194 * `dict` can be released after creation. */ |
194 ZSTDLIB_API ZSTD_DDict* ZSTD_createDDict(const void* dict, size_t dictSize); |
195 ZSTDLIB_API ZSTD_DDict* ZSTD_createDDict(const void* dict, size_t dictSize); |
195 |
196 |
196 /*! ZSTD_freeDDict() : |
197 /*! ZSTD_freeDDict() : |
197 * Function frees memory allocated with ZSTD_createDDict() */ |
198 * Function frees memory allocated with ZSTD_createDDict() */ |
198 ZSTDLIB_API size_t ZSTD_freeDDict(ZSTD_DDict* ddict); |
199 ZSTDLIB_API size_t ZSTD_freeDDict(ZSTD_DDict* ddict); |
199 |
200 |
200 /*! ZSTD_decompress_usingDDict() : |
201 /*! ZSTD_decompress_usingDDict() : |
201 * Decompression using a digested Dictionary |
202 * Decompression using a digested Dictionary. |
202 * Faster startup than ZSTD_decompress_usingDict(), recommended when same dictionary is used multiple times. */ |
203 * Faster startup than ZSTD_decompress_usingDict(), recommended when same dictionary is used multiple times. */ |
203 ZSTDLIB_API size_t ZSTD_decompress_usingDDict(ZSTD_DCtx* dctx, |
204 ZSTDLIB_API size_t ZSTD_decompress_usingDDict(ZSTD_DCtx* dctx, |
204 void* dst, size_t dstCapacity, |
205 void* dst, size_t dstCapacity, |
205 const void* src, size_t srcSize, |
206 const void* src, size_t srcSize, |
206 const ZSTD_DDict* ddict); |
207 const ZSTD_DDict* ddict); |
234 * since it will play nicer with system's memory, by re-using already allocated memory. |
235 * since it will play nicer with system's memory, by re-using already allocated memory. |
235 * Use one separate ZSTD_CStream per thread for parallel execution. |
236 * Use one separate ZSTD_CStream per thread for parallel execution. |
236 * |
237 * |
237 * Start a new compression by initializing ZSTD_CStream. |
238 * Start a new compression by initializing ZSTD_CStream. |
238 * Use ZSTD_initCStream() to start a new compression operation. |
239 * Use ZSTD_initCStream() to start a new compression operation. |
239 * Use ZSTD_initCStream_usingDict() for a compression which requires a dictionary. |
240 * Use ZSTD_initCStream_usingDict() or ZSTD_initCStream_usingCDict() for a compression which requires a dictionary (experimental section) |
240 * |
241 * |
241 * Use ZSTD_compressStream() repetitively to consume input stream. |
242 * Use ZSTD_compressStream() repetitively to consume input stream. |
242 * The function will automatically update both `pos` fields. |
243 * The function will automatically update both `pos` fields. |
243 * Note that it may not consume the entire input, in which case `pos < size`, |
244 * Note that it may not consume the entire input, in which case `pos < size`, |
244 * and it's up to the caller to present again remaining data. |
245 * and it's up to the caller to present again remaining data. |
245 * @return : a size hint, preferred nb of bytes to use as input for next function call |
246 * @return : a size hint, preferred nb of bytes to use as input for next function call |
246 * (it's just a hint, to help latency a little, any other value will work fine) |
|
247 * (note : the size hint is guaranteed to be <= ZSTD_CStreamInSize() ) |
|
248 * or an error code, which can be tested using ZSTD_isError(). |
247 * or an error code, which can be tested using ZSTD_isError(). |
249 * |
248 * Note 1 : it's just a hint, to help latency a little, any other value will work fine. |
250 * At any moment, it's possible to flush whatever data remains within buffer, using ZSTD_flushStream(). |
249 * Note 2 : size hint is guaranteed to be <= ZSTD_CStreamInSize() |
|
250 * |
|
251 * At any moment, it's possible to flush whatever data remains within internal buffer, using ZSTD_flushStream(). |
251 * `output->pos` will be updated. |
252 * `output->pos` will be updated. |
252 * Note some content might still be left within internal buffer if `output->size` is too small. |
253 * Note that some content might still be left within internal buffer if `output->size` is too small. |
253 * @return : nb of bytes still present within internal buffer (0 if it's empty) |
254 * @return : nb of bytes still present within internal buffer (0 if it's empty) |
254 * or an error code, which can be tested using ZSTD_isError(). |
255 * or an error code, which can be tested using ZSTD_isError(). |
255 * |
256 * |
256 * ZSTD_endStream() instructs to finish a frame. |
257 * ZSTD_endStream() instructs to finish a frame. |
257 * It will perform a flush and write frame epilogue. |
258 * It will perform a flush and write frame epilogue. |
258 * The epilogue is required for decoders to consider a frame completed. |
259 * The epilogue is required for decoders to consider a frame completed. |
259 * Similar to ZSTD_flushStream(), it may not be able to flush the full content if `output->size` is too small. |
260 * Similar to ZSTD_flushStream(), it may not be able to flush the full content if `output->size` is too small. |
260 * In which case, call again ZSTD_endStream() to complete the flush. |
261 * In which case, call again ZSTD_endStream() to complete the flush. |
261 * @return : nb of bytes still present within internal buffer (0 if it's empty) |
262 * @return : nb of bytes still present within internal buffer (0 if it's empty, hence compression completed) |
262 * or an error code, which can be tested using ZSTD_isError(). |
263 * or an error code, which can be tested using ZSTD_isError(). |
263 * |
264 * |
264 * *******************************************************************/ |
265 * *******************************************************************/ |
265 |
266 |
266 /*===== Streaming compression functions ======*/ |
|
267 typedef struct ZSTD_CStream_s ZSTD_CStream; |
267 typedef struct ZSTD_CStream_s ZSTD_CStream; |
268 ZSTDLIB_API ZSTD_CStream* ZSTD_createCStream(void); |
268 ZSTDLIB_API ZSTD_CStream* ZSTD_createCStream(void); |
269 ZSTDLIB_API size_t ZSTD_freeCStream(ZSTD_CStream* zcs); |
269 ZSTDLIB_API size_t ZSTD_freeCStream(ZSTD_CStream* zcs); |
|
270 |
270 ZSTDLIB_API size_t ZSTD_initCStream(ZSTD_CStream* zcs, int compressionLevel); |
271 ZSTDLIB_API size_t ZSTD_initCStream(ZSTD_CStream* zcs, int compressionLevel); |
271 ZSTDLIB_API size_t ZSTD_compressStream(ZSTD_CStream* zcs, ZSTD_outBuffer* output, ZSTD_inBuffer* input); |
272 ZSTDLIB_API size_t ZSTD_compressStream(ZSTD_CStream* zcs, ZSTD_outBuffer* output, ZSTD_inBuffer* input); |
272 ZSTDLIB_API size_t ZSTD_flushStream(ZSTD_CStream* zcs, ZSTD_outBuffer* output); |
273 ZSTDLIB_API size_t ZSTD_flushStream(ZSTD_CStream* zcs, ZSTD_outBuffer* output); |
273 ZSTDLIB_API size_t ZSTD_endStream(ZSTD_CStream* zcs, ZSTD_outBuffer* output); |
274 ZSTDLIB_API size_t ZSTD_endStream(ZSTD_CStream* zcs, ZSTD_outBuffer* output); |
274 |
275 |
293 * If `input.pos < input.size`, some input has not been consumed. |
294 * If `input.pos < input.size`, some input has not been consumed. |
294 * It's up to the caller to present again remaining data. |
295 * It's up to the caller to present again remaining data. |
295 * If `output.pos < output.size`, decoder has flushed everything it could. |
296 * If `output.pos < output.size`, decoder has flushed everything it could. |
296 * @return : 0 when a frame is completely decoded and fully flushed, |
297 * @return : 0 when a frame is completely decoded and fully flushed, |
297 * an error code, which can be tested using ZSTD_isError(), |
298 * an error code, which can be tested using ZSTD_isError(), |
298 * any other value > 0, which means there is still some work to do to complete the frame. |
299 * any other value > 0, which means there is still some decoding to do to complete current frame. |
299 * The return value is a suggested next input size (just an hint, to help latency). |
300 * The return value is a suggested next input size (a hint to improve latency) that will never load more than the current frame. |
300 * *******************************************************************************/ |
301 * *******************************************************************************/ |
301 |
302 |
302 /*===== Streaming decompression functions =====*/ |
|
303 typedef struct ZSTD_DStream_s ZSTD_DStream; |
303 typedef struct ZSTD_DStream_s ZSTD_DStream; |
304 ZSTDLIB_API ZSTD_DStream* ZSTD_createDStream(void); |
304 ZSTDLIB_API ZSTD_DStream* ZSTD_createDStream(void); |
305 ZSTDLIB_API size_t ZSTD_freeDStream(ZSTD_DStream* zds); |
305 ZSTDLIB_API size_t ZSTD_freeDStream(ZSTD_DStream* zds); |
|
306 |
306 ZSTDLIB_API size_t ZSTD_initDStream(ZSTD_DStream* zds); |
307 ZSTDLIB_API size_t ZSTD_initDStream(ZSTD_DStream* zds); |
307 ZSTDLIB_API size_t ZSTD_decompressStream(ZSTD_DStream* zds, ZSTD_outBuffer* output, ZSTD_inBuffer* input); |
308 ZSTDLIB_API size_t ZSTD_decompressStream(ZSTD_DStream* zds, ZSTD_outBuffer* output, ZSTD_inBuffer* input); |
308 |
309 |
309 ZSTDLIB_API size_t ZSTD_DStreamInSize(void); /*!< recommended size for input buffer */ |
310 ZSTDLIB_API size_t ZSTD_DStreamInSize(void); /*!< recommended size for input buffer */ |
310 ZSTDLIB_API size_t ZSTD_DStreamOutSize(void); /*!< recommended size for output buffer. Guarantee to successfully flush at least one complete block in all circumstances. */ |
311 ZSTDLIB_API size_t ZSTD_DStreamOutSize(void); /*!< recommended size for output buffer. Guarantee to successfully flush at least one complete block in all circumstances. */ |
311 |
312 |
312 |
313 #endif /* ZSTD_H_235446 */ |
313 |
314 |
314 #ifdef ZSTD_STATIC_LINKING_ONLY |
315 |
|
316 #if defined(ZSTD_STATIC_LINKING_ONLY) && !defined(ZSTD_H_ZSTD_STATIC_LINKING_ONLY) |
|
317 #define ZSTD_H_ZSTD_STATIC_LINKING_ONLY |
315 |
318 |
316 /**************************************************************************************** |
319 /**************************************************************************************** |
317 * START OF ADVANCED AND EXPERIMENTAL FUNCTIONS |
320 * START OF ADVANCED AND EXPERIMENTAL FUNCTIONS |
318 * The definitions in this section are considered experimental. |
321 * The definitions in this section are considered experimental. |
319 * They should never be used with a dynamic library, as they may change in the future. |
322 * They should never be used with a dynamic library, as they may change in the future. |
401 |
404 |
402 /*! ZSTD_sizeof_CDict() : |
405 /*! ZSTD_sizeof_CDict() : |
403 * Gives the amount of memory used by a given ZSTD_sizeof_CDict */ |
406 * Gives the amount of memory used by a given ZSTD_sizeof_CDict */ |
404 ZSTDLIB_API size_t ZSTD_sizeof_CDict(const ZSTD_CDict* cdict); |
407 ZSTDLIB_API size_t ZSTD_sizeof_CDict(const ZSTD_CDict* cdict); |
405 |
408 |
|
409 /*! ZSTD_getCParams() : |
|
410 * @return ZSTD_compressionParameters structure for a selected compression level and estimated srcSize. |
|
411 * `estimatedSrcSize` value is optional, select 0 if not known */ |
|
412 ZSTDLIB_API ZSTD_compressionParameters ZSTD_getCParams(int compressionLevel, unsigned long long estimatedSrcSize, size_t dictSize); |
|
413 |
406 /*! ZSTD_getParams() : |
414 /*! ZSTD_getParams() : |
407 * same as ZSTD_getCParams(), but @return a full `ZSTD_parameters` object instead of a `ZSTD_compressionParameters`. |
415 * same as ZSTD_getCParams(), but @return a full `ZSTD_parameters` object instead of sub-component `ZSTD_compressionParameters`. |
408 * All fields of `ZSTD_frameParameters` are set to default (0) */ |
416 * All fields of `ZSTD_frameParameters` are set to default (0) */ |
409 ZSTDLIB_API ZSTD_parameters ZSTD_getParams(int compressionLevel, unsigned long long srcSize, size_t dictSize); |
417 ZSTDLIB_API ZSTD_parameters ZSTD_getParams(int compressionLevel, unsigned long long estimatedSrcSize, size_t dictSize); |
410 |
|
411 /*! ZSTD_getCParams() : |
|
412 * @return ZSTD_compressionParameters structure for a selected compression level and srcSize. |
|
413 * `srcSize` value is optional, select 0 if not known */ |
|
414 ZSTDLIB_API ZSTD_compressionParameters ZSTD_getCParams(int compressionLevel, unsigned long long srcSize, size_t dictSize); |
|
415 |
418 |
416 /*! ZSTD_checkCParams() : |
419 /*! ZSTD_checkCParams() : |
417 * Ensure param values remain within authorized range */ |
420 * Ensure param values remain within authorized range */ |
418 ZSTDLIB_API size_t ZSTD_checkCParams(ZSTD_compressionParameters params); |
421 ZSTDLIB_API size_t ZSTD_checkCParams(ZSTD_compressionParameters params); |
419 |
422 |
447 |
457 |
448 /*! ZSTD_sizeof_DDict() : |
458 /*! ZSTD_sizeof_DDict() : |
449 * Gives the amount of memory used by a given ZSTD_DDict */ |
459 * Gives the amount of memory used by a given ZSTD_DDict */ |
450 ZSTDLIB_API size_t ZSTD_sizeof_DDict(const ZSTD_DDict* ddict); |
460 ZSTDLIB_API size_t ZSTD_sizeof_DDict(const ZSTD_DDict* ddict); |
451 |
461 |
|
462 /*! ZSTD_getDictID_fromDict() : |
|
463 * Provides the dictID stored within dictionary. |
|
464 * if @return == 0, the dictionary is not conformant with Zstandard specification. |
|
465 * It can still be loaded, but as a content-only dictionary. */ |
|
466 unsigned ZSTD_getDictID_fromDict(const void* dict, size_t dictSize); |
|
467 |
|
468 /*! ZSTD_getDictID_fromDDict() : |
|
469 * Provides the dictID of the dictionary loaded into `ddict`. |
|
470 * If @return == 0, the dictionary is not conformant to Zstandard specification, or empty. |
|
471 * Non-conformant dictionaries can still be loaded, but as content-only dictionaries. */ |
|
472 unsigned ZSTD_getDictID_fromDDict(const ZSTD_DDict* ddict); |
|
473 |
|
474 /*! ZSTD_getDictID_fromFrame() : |
|
475 * Provides the dictID required to decompressed the frame stored within `src`. |
|
476 * If @return == 0, the dictID could not be decoded. |
|
477 * This could for one of the following reasons : |
|
478 * - The frame does not require a dictionary to be decoded (most common case). |
|
479 * - The frame was built with dictID intentionally removed. Whatever dictionary is necessary is a hidden information. |
|
480 * Note : this use case also happens when using a non-conformant dictionary. |
|
481 * - `srcSize` is too small, and as a result, the frame header could not be decoded (only possible if `srcSize < ZSTD_FRAMEHEADERSIZE_MAX`). |
|
482 * - This is not a Zstandard frame. |
|
483 * When identifying the exact failure cause, it's possible to used ZSTD_getFrameParams(), which will provide a more precise error code. */ |
|
484 unsigned ZSTD_getDictID_fromFrame(const void* src, size_t srcSize); |
|
485 |
452 |
486 |
453 /******************************************************************** |
487 /******************************************************************** |
454 * Advanced streaming functions |
488 * Advanced streaming functions |
455 ********************************************************************/ |
489 ********************************************************************/ |
456 |
490 |
457 /*===== Advanced Streaming compression functions =====*/ |
491 /*===== Advanced Streaming compression functions =====*/ |
458 ZSTDLIB_API ZSTD_CStream* ZSTD_createCStream_advanced(ZSTD_customMem customMem); |
492 ZSTDLIB_API ZSTD_CStream* ZSTD_createCStream_advanced(ZSTD_customMem customMem); |
|
493 ZSTDLIB_API size_t ZSTD_initCStream_srcSize(ZSTD_CStream* zcs, int compressionLevel, unsigned long long pledgedSrcSize); /**< pledgedSrcSize must be correct */ |
459 ZSTDLIB_API size_t ZSTD_initCStream_usingDict(ZSTD_CStream* zcs, const void* dict, size_t dictSize, int compressionLevel); |
494 ZSTDLIB_API size_t ZSTD_initCStream_usingDict(ZSTD_CStream* zcs, const void* dict, size_t dictSize, int compressionLevel); |
460 ZSTDLIB_API size_t ZSTD_initCStream_advanced(ZSTD_CStream* zcs, const void* dict, size_t dictSize, |
495 ZSTDLIB_API size_t ZSTD_initCStream_advanced(ZSTD_CStream* zcs, const void* dict, size_t dictSize, |
461 ZSTD_parameters params, unsigned long long pledgedSrcSize); /**< pledgedSrcSize is optional and can be zero == unknown */ |
496 ZSTD_parameters params, unsigned long long pledgedSrcSize); /**< pledgedSrcSize is optional and can be zero == unknown */ |
462 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 */ |
497 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 */ |
463 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 */ |
498 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 */ |