blob: f2e4ce2651206b074d6ce28bacf4b01468d2c846 [file] [log] [blame]
Yann Collet4ded9e52016-08-30 10:04:33 -07001/**
2 * Copyright (c) 2016-present, Przemyslaw Skibinski, 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 */
inikep3eabe9b2016-05-12 17:15:41 +02009
10#ifndef ZSTD_ZLIBWRAPPER_H
11#define ZSTD_ZLIBWRAPPER_H
12
13#if defined (__cplusplus)
14extern "C" {
15#endif
16
17
18#define Z_PREFIX
19#include <zlib.h>
20
inikepd0c38622016-05-27 12:33:19 +020021#if !defined(z_const)
inikepbf25d7a2016-06-02 10:19:35 +020022#if ZLIB_VERNUM >= 0x1260
Yann Collet4ded9e52016-08-30 10:04:33 -070023 #define z_const const
inikepbf25d7a2016-06-02 10:19:35 +020024#else
25 #define z_const
26#endif
inikepd0c38622016-05-27 12:33:19 +020027#endif
inikep3eabe9b2016-05-12 17:15:41 +020028
inikep230a61f2016-09-21 16:46:35 +020029/* returns a string with version of zstd library */
inikep614fdde2016-06-02 18:40:41 +020030const char * zstdVersion(void);
inikep3eabe9b2016-05-12 17:15:41 +020031
inikepd7557172016-09-22 11:52:00 +020032
inikep706876f2016-09-27 16:56:07 +020033/*** COMPRESSION ***/
inikepd7557172016-09-22 11:52:00 +020034/* enables/disables zstd compression during runtime */
inikep252c20d2016-09-23 09:08:40 +020035void ZWRAP_useZSTDcompression(int turn_on);
inikepd7557172016-09-22 11:52:00 +020036
inikep706876f2016-09-27 16:56:07 +020037/* checks if zstd compression is turned on */
inikep252c20d2016-09-23 09:08:40 +020038int ZWRAP_isUsingZSTDcompression(void);
inikepd7557172016-09-22 11:52:00 +020039
inikep7e792572016-09-21 17:17:29 +020040/* Changes a pledged source size for a given compression stream.
inikepdfef5dd2016-09-22 10:23:26 +020041 It will change ZSTD compression parameters what may improve compression speed and/or ratio.
inikep572d4282016-09-27 15:25:20 +020042 The function should be called just after deflateInit() or deflateReset() and before deflate() or deflateSetDictionary().
43 It's only helpful when data is compressed in blocks.
44 There will be no change in case of deflateInit() or deflateReset() immediately followed by deflate(strm, Z_FINISH)
inikep67a1f4d2016-09-26 20:49:18 +020045 as this case is automatically detected. */
inikep252c20d2016-09-23 09:08:40 +020046int ZWRAP_setPledgedSrcSize(z_streamp strm, unsigned long long pledgedSrcSize);
inikep230a61f2016-09-21 16:46:35 +020047
inikep856f91e2016-09-27 17:14:04 +020048/* Similar to deflateReset but preserves dictionary set using deflateSetDictionary.
49 It should improve compression speed because there will be less calls to deflateSetDictionary
50 When using zlib compression this method redirects to deflateReset. */
inikep706876f2016-09-27 16:56:07 +020051int ZWRAP_deflateResetWithoutDict(z_streamp strm);
inikep3eabe9b2016-05-12 17:15:41 +020052
inikep706876f2016-09-27 16:56:07 +020053
inikep856f91e2016-09-27 17:14:04 +020054
inikep706876f2016-09-27 16:56:07 +020055/*** DECOMPRESSION ***/
inikep252c20d2016-09-23 09:08:40 +020056typedef enum { ZWRAP_FORCE_ZLIB, ZWRAP_AUTO } ZWRAP_decompress_type;
inikepd7557172016-09-22 11:52:00 +020057
58/* enables/disables automatic recognition of zstd/zlib compressed data during runtime */
inikep252c20d2016-09-23 09:08:40 +020059void ZWRAP_setDecompressionType(ZWRAP_decompress_type type);
inikepd7557172016-09-22 11:52:00 +020060
inikep706876f2016-09-27 16:56:07 +020061/* checks zstd decompression type */
inikep252c20d2016-09-23 09:08:40 +020062ZWRAP_decompress_type ZWRAP_getDecompressionType(void);
inikepd7557172016-09-22 11:52:00 +020063
inikep706876f2016-09-27 16:56:07 +020064/* checks if zstd decompression is used for a given stream */
65int ZWRAP_isUsingZSTDdecompression(z_streamp strm);
inikepd7557172016-09-22 11:52:00 +020066
inikep706876f2016-09-27 16:56:07 +020067/* Similar to inflateReset but preserves dictionary set using inflateSetDictionary.
inikep856f91e2016-09-27 17:14:04 +020068 inflate() will return Z_NEED_DICT only for the first time what will improve decompression speed.
69 For zlib streams this method redirects to inflateReset. */
inikep706876f2016-09-27 16:56:07 +020070int ZWRAP_inflateResetWithoutDict(z_streamp strm);
inikepd7557172016-09-22 11:52:00 +020071
72
inikep3eabe9b2016-05-12 17:15:41 +020073#if defined (__cplusplus)
74}
75#endif
76
77#endif /* ZSTD_ZLIBWRAPPER_H */