Path: blob/main/sys/contrib/zstd/zlibWrapper/zstd_zlibwrapper.h
48255 views
/*1* Copyright (c) 2016-2021, Przemyslaw Skibinski, Yann Collet, Facebook, Inc.2* All rights reserved.3*4* This source code is licensed under both the BSD-style license (found in the5* LICENSE file in the root directory of this source tree) and the GPLv2 (found6* in the COPYING file in the root directory of this source tree).7* You may select, at your option, one of the above-listed licenses.8*/910#ifndef ZSTD_ZLIBWRAPPER_H11#define ZSTD_ZLIBWRAPPER_H1213#if defined (__cplusplus)14extern "C" {15#endif161718#define ZLIB_CONST19#define Z_PREFIX20#define ZLIB_INTERNAL /* disables gz*64 functions but fixes zlib 1.2.4 with Z_PREFIX */21#include <zlib.h>2223#if !defined(z_const)24#define z_const25#endif262728/* returns a string with version of zstd library */29const char * zstdVersion(void);303132/*** COMPRESSION ***/33/* ZWRAP_useZSTDcompression() enables/disables zstd compression during runtime.34By default zstd compression is disabled. To enable zstd compression please use one of the methods:35- compilation with the additional option -DZWRAP_USE_ZSTD=136- using '#define ZWRAP_USE_ZSTD 1' in source code before '#include "zstd_zlibwrapper.h"'37- calling ZWRAP_useZSTDcompression(1)38All above-mentioned methods will enable zstd compression for all threads.39Be aware that ZWRAP_useZSTDcompression() is not thread-safe and may lead to a race condition. */40void ZWRAP_useZSTDcompression(int turn_on);4142/* checks if zstd compression is turned on */43int ZWRAP_isUsingZSTDcompression(void);4445/* Changes a pledged source size for a given compression stream.46It will change ZSTD compression parameters what may improve compression speed and/or ratio.47The function should be called just after deflateInit() or deflateReset() and before deflate() or deflateSetDictionary().48It's only helpful when data is compressed in blocks.49There will be no change in case of deflateInit() or deflateReset() immediately followed by deflate(strm, Z_FINISH)50as this case is automatically detected. */51int ZWRAP_setPledgedSrcSize(z_streamp strm, unsigned long long pledgedSrcSize);5253/* Similar to deflateReset but preserves dictionary set using deflateSetDictionary.54It should improve compression speed because there will be less calls to deflateSetDictionary55When using zlib compression this method redirects to deflateReset. */56int ZWRAP_deflateReset_keepDict(z_streamp strm);57585960/*** DECOMPRESSION ***/61typedef enum { ZWRAP_FORCE_ZLIB, ZWRAP_AUTO } ZWRAP_decompress_type;6263/* ZWRAP_setDecompressionType() enables/disables automatic recognition of zstd/zlib compressed data during runtime.64By default auto-detection of zstd and zlib streams in enabled (ZWRAP_AUTO).65Forcing zlib decompression with ZWRAP_setDecompressionType(ZWRAP_FORCE_ZLIB) slightly improves66decompression speed of zlib-encoded streams.67Be aware that ZWRAP_setDecompressionType() is not thread-safe and may lead to a race condition. */68void ZWRAP_setDecompressionType(ZWRAP_decompress_type type);6970/* checks zstd decompression type */71ZWRAP_decompress_type ZWRAP_getDecompressionType(void);7273/* Checks if zstd decompression is used for a given stream.74If will return 1 only when inflate() was called and zstd header was detected. */75int ZWRAP_isUsingZSTDdecompression(z_streamp strm);7677/* Similar to inflateReset but preserves dictionary set using inflateSetDictionary.78inflate() will return Z_NEED_DICT only for the first time what will improve decompression speed.79For zlib streams this method redirects to inflateReset. */80int ZWRAP_inflateReset_keepDict(z_streamp strm);818283#if defined (__cplusplus)84}85#endif8687#endif /* ZSTD_ZLIBWRAPPER_H */888990