1*22ce4affSfengbojiang /* 2*22ce4affSfengbojiang * Copyright (c) 2016-2020, Przemyslaw Skibinski, Yann Collet, Facebook, Inc. 3*22ce4affSfengbojiang * All rights reserved. 4*22ce4affSfengbojiang * 5*22ce4affSfengbojiang * This source code is licensed under both the BSD-style license (found in the 6*22ce4affSfengbojiang * LICENSE file in the root directory of this source tree) and the GPLv2 (found 7*22ce4affSfengbojiang * in the COPYING file in the root directory of this source tree). 8*22ce4affSfengbojiang * You may select, at your option, one of the above-listed licenses. 9*22ce4affSfengbojiang */ 10*22ce4affSfengbojiang 11*22ce4affSfengbojiang #ifndef ZSTD_ZLIBWRAPPER_H 12*22ce4affSfengbojiang #define ZSTD_ZLIBWRAPPER_H 13*22ce4affSfengbojiang 14*22ce4affSfengbojiang #if defined (__cplusplus) 15*22ce4affSfengbojiang extern "C" { 16*22ce4affSfengbojiang #endif 17*22ce4affSfengbojiang 18*22ce4affSfengbojiang 19*22ce4affSfengbojiang #define ZLIB_CONST 20*22ce4affSfengbojiang #define Z_PREFIX 21*22ce4affSfengbojiang #define ZLIB_INTERNAL /* disables gz*64 functions but fixes zlib 1.2.4 with Z_PREFIX */ 22*22ce4affSfengbojiang #include <zlib.h> 23*22ce4affSfengbojiang 24*22ce4affSfengbojiang #if !defined(z_const) 25*22ce4affSfengbojiang #define z_const 26*22ce4affSfengbojiang #endif 27*22ce4affSfengbojiang 28*22ce4affSfengbojiang 29*22ce4affSfengbojiang /* returns a string with version of zstd library */ 30*22ce4affSfengbojiang const char * zstdVersion(void); 31*22ce4affSfengbojiang 32*22ce4affSfengbojiang 33*22ce4affSfengbojiang /*** COMPRESSION ***/ 34*22ce4affSfengbojiang /* ZWRAP_useZSTDcompression() enables/disables zstd compression during runtime. 35*22ce4affSfengbojiang By default zstd compression is disabled. To enable zstd compression please use one of the methods: 36*22ce4affSfengbojiang - compilation with the additional option -DZWRAP_USE_ZSTD=1 37*22ce4affSfengbojiang - using '#define ZWRAP_USE_ZSTD 1' in source code before '#include "zstd_zlibwrapper.h"' 38*22ce4affSfengbojiang - calling ZWRAP_useZSTDcompression(1) 39*22ce4affSfengbojiang All above-mentioned methods will enable zstd compression for all threads. 40*22ce4affSfengbojiang Be aware that ZWRAP_useZSTDcompression() is not thread-safe and may lead to a race condition. */ 41*22ce4affSfengbojiang void ZWRAP_useZSTDcompression(int turn_on); 42*22ce4affSfengbojiang 43*22ce4affSfengbojiang /* checks if zstd compression is turned on */ 44*22ce4affSfengbojiang int ZWRAP_isUsingZSTDcompression(void); 45*22ce4affSfengbojiang 46*22ce4affSfengbojiang /* Changes a pledged source size for a given compression stream. 47*22ce4affSfengbojiang It will change ZSTD compression parameters what may improve compression speed and/or ratio. 48*22ce4affSfengbojiang The function should be called just after deflateInit() or deflateReset() and before deflate() or deflateSetDictionary(). 49*22ce4affSfengbojiang It's only helpful when data is compressed in blocks. 50*22ce4affSfengbojiang There will be no change in case of deflateInit() or deflateReset() immediately followed by deflate(strm, Z_FINISH) 51*22ce4affSfengbojiang as this case is automatically detected. */ 52*22ce4affSfengbojiang int ZWRAP_setPledgedSrcSize(z_streamp strm, unsigned long long pledgedSrcSize); 53*22ce4affSfengbojiang 54*22ce4affSfengbojiang /* Similar to deflateReset but preserves dictionary set using deflateSetDictionary. 55*22ce4affSfengbojiang It should improve compression speed because there will be less calls to deflateSetDictionary 56*22ce4affSfengbojiang When using zlib compression this method redirects to deflateReset. */ 57*22ce4affSfengbojiang int ZWRAP_deflateReset_keepDict(z_streamp strm); 58*22ce4affSfengbojiang 59*22ce4affSfengbojiang 60*22ce4affSfengbojiang 61*22ce4affSfengbojiang /*** DECOMPRESSION ***/ 62*22ce4affSfengbojiang typedef enum { ZWRAP_FORCE_ZLIB, ZWRAP_AUTO } ZWRAP_decompress_type; 63*22ce4affSfengbojiang 64*22ce4affSfengbojiang /* ZWRAP_setDecompressionType() enables/disables automatic recognition of zstd/zlib compressed data during runtime. 65*22ce4affSfengbojiang By default auto-detection of zstd and zlib streams in enabled (ZWRAP_AUTO). 66*22ce4affSfengbojiang Forcing zlib decompression with ZWRAP_setDecompressionType(ZWRAP_FORCE_ZLIB) slightly improves 67*22ce4affSfengbojiang decompression speed of zlib-encoded streams. 68*22ce4affSfengbojiang Be aware that ZWRAP_setDecompressionType() is not thread-safe and may lead to a race condition. */ 69*22ce4affSfengbojiang void ZWRAP_setDecompressionType(ZWRAP_decompress_type type); 70*22ce4affSfengbojiang 71*22ce4affSfengbojiang /* checks zstd decompression type */ 72*22ce4affSfengbojiang ZWRAP_decompress_type ZWRAP_getDecompressionType(void); 73*22ce4affSfengbojiang 74*22ce4affSfengbojiang /* Checks if zstd decompression is used for a given stream. 75*22ce4affSfengbojiang If will return 1 only when inflate() was called and zstd header was detected. */ 76*22ce4affSfengbojiang int ZWRAP_isUsingZSTDdecompression(z_streamp strm); 77*22ce4affSfengbojiang 78*22ce4affSfengbojiang /* Similar to inflateReset but preserves dictionary set using inflateSetDictionary. 79*22ce4affSfengbojiang inflate() will return Z_NEED_DICT only for the first time what will improve decompression speed. 80*22ce4affSfengbojiang For zlib streams this method redirects to inflateReset. */ 81*22ce4affSfengbojiang int ZWRAP_inflateReset_keepDict(z_streamp strm); 82*22ce4affSfengbojiang 83*22ce4affSfengbojiang 84*22ce4affSfengbojiang #if defined (__cplusplus) 85*22ce4affSfengbojiang } 86*22ce4affSfengbojiang #endif 87*22ce4affSfengbojiang 88*22ce4affSfengbojiang #endif /* ZSTD_ZLIBWRAPPER_H */ 89