blob: e791043e1d0c430b8a01b42cda49a8c03736702c [file] [log] [blame]
Yann Collet32fb4072017-08-18 16:52:05 -07001/*
Nick Terrellac58c8d2020-03-26 15:19:05 -07002 * Copyright (c) 2016-2020, Przemyslaw Skibinski, Yann Collet, Facebook, Inc.
Yann Collet4ded9e52016-08-30 10:04:33 -07003 * All rights reserved.
4 *
Yann Collet32fb4072017-08-18 16:52:05 -07005 * This source code is licensed under both the BSD-style license (found in the
6 * LICENSE file in the root directory of this source tree) and the GPLv2 (found
7 * in the COPYING file in the root directory of this source tree).
Yann Collet3128e032017-09-08 00:09:23 -07008 * You may select, at your option, one of the above-listed licenses.
Yann Collet4ded9e52016-08-30 10:04:33 -07009 */
inikep3eabe9b2016-05-12 17:15:41 +020010
11#ifndef ZSTD_ZLIBWRAPPER_H
12#define ZSTD_ZLIBWRAPPER_H
13
14#if defined (__cplusplus)
15extern "C" {
16#endif
17
18
Przemyslaw Skibinski6cecb352016-11-04 17:49:17 +010019#define ZLIB_CONST
inikep3eabe9b2016-05-12 17:15:41 +020020#define Z_PREFIX
Przemyslaw Skibinskic77befe2016-11-28 14:09:26 +010021#define ZLIB_INTERNAL /* disables gz*64 functions but fixes zlib 1.2.4 with Z_PREFIX */
inikep3eabe9b2016-05-12 17:15:41 +020022#include <zlib.h>
23
inikepd0c38622016-05-27 12:33:19 +020024#if !defined(z_const)
inikepbf25d7a2016-06-02 10:19:35 +020025 #define z_const
26#endif
Przemyslaw Skibinski6cecb352016-11-04 17:49:17 +010027
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 ***/
Przemyslaw Skibinski5c42aad2017-02-23 18:28:48 +010034/* ZWRAP_useZSTDcompression() enables/disables zstd compression during runtime.
35 By default zstd compression is disabled. To enable zstd compression please use one of the methods:
Yann Collet32fb4072017-08-18 16:52:05 -070036 - compilation with the additional option -DZWRAP_USE_ZSTD=1
Przemyslaw Skibinski5c42aad2017-02-23 18:28:48 +010037 - using '#define ZWRAP_USE_ZSTD 1' in source code before '#include "zstd_zlibwrapper.h"'
38 - calling ZWRAP_useZSTDcompression(1)
39 All above-mentioned methods will enable zstd compression for all threads.
40 Be aware that ZWRAP_useZSTDcompression() is not thread-safe and may lead to a race condition. */
inikep252c20d2016-09-23 09:08:40 +020041void ZWRAP_useZSTDcompression(int turn_on);
inikepd7557172016-09-22 11:52:00 +020042
inikep706876f2016-09-27 16:56:07 +020043/* checks if zstd compression is turned on */
inikep252c20d2016-09-23 09:08:40 +020044int ZWRAP_isUsingZSTDcompression(void);
inikepd7557172016-09-22 11:52:00 +020045
inikep7e792572016-09-21 17:17:29 +020046/* Changes a pledged source size for a given compression stream.
inikepdfef5dd2016-09-22 10:23:26 +020047 It will change ZSTD compression parameters what may improve compression speed and/or ratio.
inikep572d4282016-09-27 15:25:20 +020048 The function should be called just after deflateInit() or deflateReset() and before deflate() or deflateSetDictionary().
Yann Collet32fb4072017-08-18 16:52:05 -070049 It's only helpful when data is compressed in blocks.
50 There will be no change in case of deflateInit() or deflateReset() immediately followed by deflate(strm, Z_FINISH)
inikep67a1f4d2016-09-26 20:49:18 +020051 as this case is automatically detected. */
inikep252c20d2016-09-23 09:08:40 +020052int ZWRAP_setPledgedSrcSize(z_streamp strm, unsigned long long pledgedSrcSize);
inikep230a61f2016-09-21 16:46:35 +020053
inikep856f91e2016-09-27 17:14:04 +020054/* Similar to deflateReset but preserves dictionary set using deflateSetDictionary.
Yann Collet32fb4072017-08-18 16:52:05 -070055 It should improve compression speed because there will be less calls to deflateSetDictionary
inikep856f91e2016-09-27 17:14:04 +020056 When using zlib compression this method redirects to deflateReset. */
inikep20859af2016-09-27 17:27:43 +020057int ZWRAP_deflateReset_keepDict(z_streamp strm);
inikep3eabe9b2016-05-12 17:15:41 +020058
inikep706876f2016-09-27 16:56:07 +020059
inikep856f91e2016-09-27 17:14:04 +020060
inikep706876f2016-09-27 16:56:07 +020061/*** DECOMPRESSION ***/
inikep252c20d2016-09-23 09:08:40 +020062typedef enum { ZWRAP_FORCE_ZLIB, ZWRAP_AUTO } ZWRAP_decompress_type;
inikepd7557172016-09-22 11:52:00 +020063
Przemyslaw Skibinski5c42aad2017-02-23 18:28:48 +010064/* ZWRAP_setDecompressionType() enables/disables automatic recognition of zstd/zlib compressed data during runtime.
65 By default auto-detection of zstd and zlib streams in enabled (ZWRAP_AUTO).
66 Forcing zlib decompression with ZWRAP_setDecompressionType(ZWRAP_FORCE_ZLIB) slightly improves
67 decompression speed of zlib-encoded streams.
68 Be aware that ZWRAP_setDecompressionType() is not thread-safe and may lead to a race condition. */
inikep252c20d2016-09-23 09:08:40 +020069void ZWRAP_setDecompressionType(ZWRAP_decompress_type type);
inikepd7557172016-09-22 11:52:00 +020070
inikep706876f2016-09-27 16:56:07 +020071/* checks zstd decompression type */
inikep252c20d2016-09-23 09:08:40 +020072ZWRAP_decompress_type ZWRAP_getDecompressionType(void);
inikepd7557172016-09-22 11:52:00 +020073
inikep22e27302016-09-27 18:21:17 +020074/* Checks if zstd decompression is used for a given stream.
75 If will return 1 only when inflate() was called and zstd header was detected. */
inikep706876f2016-09-27 16:56:07 +020076int ZWRAP_isUsingZSTDdecompression(z_streamp strm);
inikepd7557172016-09-22 11:52:00 +020077
inikep706876f2016-09-27 16:56:07 +020078/* Similar to inflateReset but preserves dictionary set using inflateSetDictionary.
inikep856f91e2016-09-27 17:14:04 +020079 inflate() will return Z_NEED_DICT only for the first time what will improve decompression speed.
80 For zlib streams this method redirects to inflateReset. */
inikep20859af2016-09-27 17:27:43 +020081int ZWRAP_inflateReset_keepDict(z_streamp strm);
inikepd7557172016-09-22 11:52:00 +020082
83
inikep3eabe9b2016-05-12 17:15:41 +020084#if defined (__cplusplus)
85}
86#endif
87
88#endif /* ZSTD_ZLIBWRAPPER_H */