blob: 0f0fc2b03fc61e80fac560ca293b7b8609f66a6a [file] [log] [blame]
Yann Collet32fb4072017-08-18 16:52:05 -07001/*
cyan49732e3b6592017-01-20 14:00:41 -08002 * Copyright (c) 2016-present, Yann Collet, Facebook, Inc.
3 * 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).
cyan49732e3b6592017-01-20 14:00:41 -08008 */
Yann Collet3d93f2f2016-12-27 07:19:36 +01009
Nick Terrellb42dd272017-01-27 16:00:19 -080010 #ifndef ZSTDMT_COMPRESS_H
11 #define ZSTDMT_COMPRESS_H
12
13 #if defined (__cplusplus)
14 extern "C" {
15 #endif
16
Yann Collet512cbe82017-01-24 17:02:26 -080017
Yann Collet49af4182017-07-05 17:20:52 -070018/* Note : This is an internal API.
Yann Collet052a95f2017-07-11 17:18:26 -070019 * Some methods are still exposed (ZSTDLIB_API),
20 * because it used to be the only way to invoke MT compression.
Yann Collet49af4182017-07-05 17:20:52 -070021 * Now, it's recommended to use ZSTD_compress_generic() instead.
22 * These methods will stop being exposed in a future version */
Yann Collet512cbe82017-01-24 17:02:26 -080023
Yann Collet107bcbb2017-01-12 01:25:46 +010024/* === Dependencies === */
Yann Colletb44ab822017-06-20 14:11:49 -070025#include <stddef.h> /* size_t */
Yann Collet19d670b2017-01-19 15:32:07 -080026#define ZSTD_STATIC_LINKING_ONLY /* ZSTD_parameters */
Yann Colletb44ab822017-06-20 14:11:49 -070027#include "zstd.h" /* ZSTD_inBuffer, ZSTD_outBuffer, ZSTDLIB_API */
Yann Collet107bcbb2017-01-12 01:25:46 +010028
29
Yann Colletc4a5a212017-06-01 17:56:14 -070030/* === Memory management === */
Yann Collet3d93f2f2016-12-27 07:19:36 +010031typedef struct ZSTDMT_CCtx_s ZSTDMT_CCtx;
Yann Collet317604e2017-01-20 17:18:41 -080032ZSTDLIB_API ZSTDMT_CCtx* ZSTDMT_createCCtx(unsigned nbThreads);
Yann Colletc4a5a212017-06-01 17:56:14 -070033ZSTDLIB_API ZSTDMT_CCtx* ZSTDMT_createCCtx_advanced(unsigned nbThreads,
34 ZSTD_customMem cMem);
35ZSTDLIB_API size_t ZSTDMT_freeCCtx(ZSTDMT_CCtx* mtctx);
Yann Collet3d93f2f2016-12-27 07:19:36 +010036
Yann Colletc4a5a212017-06-01 17:56:14 -070037ZSTDLIB_API size_t ZSTDMT_sizeof_CCtx(ZSTDMT_CCtx* mtctx);
Yann Colletc4a5a212017-06-01 17:56:14 -070038
39
40/* === Simple buffer-to-butter one-pass function === */
41
42ZSTDLIB_API size_t ZSTDMT_compressCCtx(ZSTDMT_CCtx* mtctx,
Yann Colletb877e832017-06-02 13:47:11 -070043 void* dst, size_t dstCapacity,
44 const void* src, size_t srcSize,
45 int compressionLevel);
Yann Collet107bcbb2017-01-12 01:25:46 +010046
47
Yann Colletd5c046c2017-06-30 14:51:01 -070048
Yann Collet107bcbb2017-01-12 01:25:46 +010049/* === Streaming functions === */
50
Yann Collet512cbe82017-01-24 17:02:26 -080051ZSTDLIB_API size_t ZSTDMT_initCStream(ZSTDMT_CCtx* mtctx, int compressionLevel);
52ZSTDLIB_API size_t ZSTDMT_resetCStream(ZSTDMT_CCtx* mtctx, unsigned long long pledgedSrcSize); /**< pledgedSrcSize is optional and can be zero == unknown */
Yann Collet19d670b2017-01-19 15:32:07 -080053
Yann Collet512cbe82017-01-24 17:02:26 -080054ZSTDLIB_API size_t ZSTDMT_compressStream(ZSTDMT_CCtx* mtctx, ZSTD_outBuffer* output, ZSTD_inBuffer* input);
Yann Collet19d670b2017-01-19 15:32:07 -080055
Yann Collet512cbe82017-01-24 17:02:26 -080056ZSTDLIB_API size_t ZSTDMT_flushStream(ZSTDMT_CCtx* mtctx, ZSTD_outBuffer* output); /**< @return : 0 == all flushed; >0 : still some data to be flushed; or an error code (ZSTD_isError()) */
57ZSTDLIB_API size_t ZSTDMT_endStream(ZSTDMT_CCtx* mtctx, ZSTD_outBuffer* output); /**< @return : 0 == all flushed; >0 : still some data to be flushed; or an error code (ZSTD_isError()) */
58
59
60/* === Advanced functions and parameters === */
61
62#ifndef ZSTDMT_SECTION_SIZE_MIN
63# define ZSTDMT_SECTION_SIZE_MIN (1U << 20) /* 1 MB - Minimum size of each compression job */
64#endif
65
Yann Colletd5c046c2017-06-30 14:51:01 -070066ZSTDLIB_API size_t ZSTDMT_compress_advanced(ZSTDMT_CCtx* mtctx,
67 void* dst, size_t dstCapacity,
68 const void* src, size_t srcSize,
69 const ZSTD_CDict* cdict,
70 ZSTD_parameters const params,
Yann Collet132e6ef2017-07-13 02:22:58 -070071 unsigned overlapLog);
Yann Colletd5c046c2017-06-30 14:51:01 -070072
Yann Collet58e8d792017-06-02 18:20:48 -070073ZSTDLIB_API size_t ZSTDMT_initCStream_advanced(ZSTDMT_CCtx* mtctx,
74 const void* dict, size_t dictSize, /* dict can be released after init, a local copy is preserved within zcs */
75 ZSTD_parameters params,
76 unsigned long long pledgedSrcSize); /* pledgedSrcSize is optional and can be zero == unknown */
Yann Collet512cbe82017-01-24 17:02:26 -080077
Yann Collet8c910d22017-06-03 01:15:02 -070078ZSTDLIB_API size_t ZSTDMT_initCStream_usingCDict(ZSTDMT_CCtx* mtctx,
79 const ZSTD_CDict* cdict,
80 ZSTD_frameParameters fparams,
81 unsigned long long pledgedSrcSize); /* note : zero means empty */
Yann Colletae728a42017-05-30 17:11:39 -070082
Yann Collet512cbe82017-01-24 17:02:26 -080083/* ZSDTMT_parameter :
84 * List of parameters that can be set using ZSTDMT_setMTCtxParameter() */
Yann Collet06e76972017-01-25 16:39:03 -080085typedef enum {
Yann Collet8dafb1a2017-01-25 17:01:13 -080086 ZSTDMT_p_sectionSize, /* size of input "section". Each section is compressed in parallel. 0 means default, which is dynamically determined within compression functions */
Yann Collet88df1ae2017-01-30 11:00:00 -080087 ZSTDMT_p_overlapSectionLog /* Log of overlapped section; 0 == no overlap, 6(default) == use 1/8th of window, >=9 == use full window */
Yann Collet06e76972017-01-25 16:39:03 -080088} ZSDTMT_parameter;
Yann Collet512cbe82017-01-24 17:02:26 -080089
90/* ZSTDMT_setMTCtxParameter() :
91 * allow setting individual parameters, one at a time, among a list of enums defined in ZSTDMT_parameter.
92 * The function must be called typically after ZSTD_createCCtx().
93 * Parameters not explicitly reset by ZSTDMT_init*() remain the same in consecutive compression sessions.
94 * @return : 0, or an error code (which can be tested using ZSTD_isError()) */
Yann Colletdc8dae52017-01-24 22:32:12 -080095ZSTDLIB_API size_t ZSTDMT_setMTCtxParameter(ZSTDMT_CCtx* mtctx, ZSDTMT_parameter parameter, unsigned value);
Nick Terrellb42dd272017-01-27 16:00:19 -080096
97
Yann Colletf35e2de2017-06-05 18:32:48 -070098/*! ZSTDMT_compressStream_generic() :
99 * Combines ZSTDMT_compressStream() with ZSTDMT_flushStream() or ZSTDMT_endStream()
Yann Colletb44ab822017-06-20 14:11:49 -0700100 * depending on flush directive.
Yann Colletf35e2de2017-06-05 18:32:48 -0700101 * @return : minimum amount of data still to be flushed
102 * 0 if fully flushed
103 * or an error code */
104ZSTDLIB_API size_t ZSTDMT_compressStream_generic(ZSTDMT_CCtx* mtctx,
105 ZSTD_outBuffer* output,
106 ZSTD_inBuffer* input,
107 ZSTD_EndDirective endOp);
108
109
110
Nick Terrellb42dd272017-01-27 16:00:19 -0800111#if defined (__cplusplus)
112}
113#endif
114
115#endif /* ZSTDMT_COMPRESS_H */