blob: fad63b6d8610b6c5485562818628f9102826c0b3 [file] [log] [blame]
cyan49732e3b6592017-01-20 14:00:41 -08001/**
2 * Copyright (c) 2016-present, Yann Collet, 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 */
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 Colletb44ab822017-06-20 14:11:49 -070018/* Note : All prototypes defined in this file are labelled experimental.
19 * No guarantee of API continuity is provided on any of them.
20 * In fact, the expectation is that these prototypes will be replaced
21 * by ZSTD_compress_generic() API in the near future */
Yann Collet512cbe82017-01-24 17:02:26 -080022
Yann Collet107bcbb2017-01-12 01:25:46 +010023/* === Dependencies === */
Yann Colletb44ab822017-06-20 14:11:49 -070024#include <stddef.h> /* size_t */
Yann Collet19d670b2017-01-19 15:32:07 -080025#define ZSTD_STATIC_LINKING_ONLY /* ZSTD_parameters */
Yann Colletb44ab822017-06-20 14:11:49 -070026#include "zstd.h" /* ZSTD_inBuffer, ZSTD_outBuffer, ZSTDLIB_API */
Yann Collet107bcbb2017-01-12 01:25:46 +010027
28
Yann Colletc4a5a212017-06-01 17:56:14 -070029/* === Memory management === */
Yann Collet3d93f2f2016-12-27 07:19:36 +010030typedef struct ZSTDMT_CCtx_s ZSTDMT_CCtx;
Yann Collet317604e2017-01-20 17:18:41 -080031ZSTDLIB_API ZSTDMT_CCtx* ZSTDMT_createCCtx(unsigned nbThreads);
Yann Colletc4a5a212017-06-01 17:56:14 -070032ZSTDLIB_API ZSTDMT_CCtx* ZSTDMT_createCCtx_advanced(unsigned nbThreads,
33 ZSTD_customMem cMem);
34ZSTDLIB_API size_t ZSTDMT_freeCCtx(ZSTDMT_CCtx* mtctx);
Yann Collet3d93f2f2016-12-27 07:19:36 +010035
Yann Colletc4a5a212017-06-01 17:56:14 -070036ZSTDLIB_API size_t ZSTDMT_sizeof_CCtx(ZSTDMT_CCtx* mtctx);
Yann Colletc4a5a212017-06-01 17:56:14 -070037
38
39/* === Simple buffer-to-butter one-pass function === */
40
41ZSTDLIB_API size_t ZSTDMT_compressCCtx(ZSTDMT_CCtx* mtctx,
Yann Colletb877e832017-06-02 13:47:11 -070042 void* dst, size_t dstCapacity,
43 const void* src, size_t srcSize,
44 int compressionLevel);
Yann Collet107bcbb2017-01-12 01:25:46 +010045
46
Yann Colletd5c046c2017-06-30 14:51:01 -070047
Yann Collet107bcbb2017-01-12 01:25:46 +010048/* === Streaming functions === */
49
Yann Collet512cbe82017-01-24 17:02:26 -080050ZSTDLIB_API size_t ZSTDMT_initCStream(ZSTDMT_CCtx* mtctx, int compressionLevel);
51ZSTDLIB_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 -080052
Yann Collet512cbe82017-01-24 17:02:26 -080053ZSTDLIB_API size_t ZSTDMT_compressStream(ZSTDMT_CCtx* mtctx, ZSTD_outBuffer* output, ZSTD_inBuffer* input);
Yann Collet19d670b2017-01-19 15:32:07 -080054
Yann Collet512cbe82017-01-24 17:02:26 -080055ZSTDLIB_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()) */
56ZSTDLIB_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()) */
57
58
59/* === Advanced functions and parameters === */
60
61#ifndef ZSTDMT_SECTION_SIZE_MIN
62# define ZSTDMT_SECTION_SIZE_MIN (1U << 20) /* 1 MB - Minimum size of each compression job */
63#endif
64
Yann Colletd5c046c2017-06-30 14:51:01 -070065ZSTDLIB_API size_t ZSTDMT_compress_advanced(ZSTDMT_CCtx* mtctx,
66 void* dst, size_t dstCapacity,
67 const void* src, size_t srcSize,
68 const ZSTD_CDict* cdict,
69 ZSTD_parameters const params,
70 unsigned overlapRLog);
71
Yann Collet58e8d792017-06-02 18:20:48 -070072ZSTDLIB_API size_t ZSTDMT_initCStream_advanced(ZSTDMT_CCtx* mtctx,
73 const void* dict, size_t dictSize, /* dict can be released after init, a local copy is preserved within zcs */
74 ZSTD_parameters params,
75 unsigned long long pledgedSrcSize); /* pledgedSrcSize is optional and can be zero == unknown */
Yann Collet512cbe82017-01-24 17:02:26 -080076
Yann Collet8c910d22017-06-03 01:15:02 -070077ZSTDLIB_API size_t ZSTDMT_initCStream_usingCDict(ZSTDMT_CCtx* mtctx,
78 const ZSTD_CDict* cdict,
79 ZSTD_frameParameters fparams,
80 unsigned long long pledgedSrcSize); /* note : zero means empty */
Yann Colletae728a42017-05-30 17:11:39 -070081
Yann Collet512cbe82017-01-24 17:02:26 -080082/* ZSDTMT_parameter :
83 * List of parameters that can be set using ZSTDMT_setMTCtxParameter() */
Yann Collet06e76972017-01-25 16:39:03 -080084typedef enum {
Yann Collet8dafb1a2017-01-25 17:01:13 -080085 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 -080086 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 -080087} ZSDTMT_parameter;
Yann Collet512cbe82017-01-24 17:02:26 -080088
89/* ZSTDMT_setMTCtxParameter() :
90 * allow setting individual parameters, one at a time, among a list of enums defined in ZSTDMT_parameter.
91 * The function must be called typically after ZSTD_createCCtx().
92 * Parameters not explicitly reset by ZSTDMT_init*() remain the same in consecutive compression sessions.
93 * @return : 0, or an error code (which can be tested using ZSTD_isError()) */
Yann Colletdc8dae52017-01-24 22:32:12 -080094ZSTDLIB_API size_t ZSTDMT_setMTCtxParameter(ZSTDMT_CCtx* mtctx, ZSDTMT_parameter parameter, unsigned value);
Nick Terrellb42dd272017-01-27 16:00:19 -080095
96
Yann Colletf35e2de2017-06-05 18:32:48 -070097/*! ZSTDMT_compressStream_generic() :
98 * Combines ZSTDMT_compressStream() with ZSTDMT_flushStream() or ZSTDMT_endStream()
Yann Colletb44ab822017-06-20 14:11:49 -070099 * depending on flush directive.
Yann Colletf35e2de2017-06-05 18:32:48 -0700100 * @return : minimum amount of data still to be flushed
101 * 0 if fully flushed
102 * or an error code */
103ZSTDLIB_API size_t ZSTDMT_compressStream_generic(ZSTDMT_CCtx* mtctx,
104 ZSTD_outBuffer* output,
105 ZSTD_inBuffer* input,
106 ZSTD_EndDirective endOp);
107
108
109
Nick Terrellb42dd272017-01-27 16:00:19 -0800110#if defined (__cplusplus)
111}
112#endif
113
114#endif /* ZSTDMT_COMPRESS_H */