zstdmt_compress.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. /*
  2. * Copyright (c) 2016-present, Yann Collet, Facebook, Inc.
  3. * All rights reserved.
  4. *
  5. * 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).
  8. * You may select, at your option, one of the above-listed licenses.
  9. */
  10. #ifndef ZSTDMT_COMPRESS_H
  11. #define ZSTDMT_COMPRESS_H
  12. #if defined (__cplusplus)
  13. extern "C" {
  14. #endif
  15. /* Note : This is an internal API.
  16. * Some methods are still exposed (ZSTDLIB_API),
  17. * because it used to be the only way to invoke MT compression.
  18. * Now, it's recommended to use ZSTD_compress_generic() instead.
  19. * These methods will stop being exposed in a future version */
  20. /* === Dependencies === */
  21. #include <stddef.h> /* size_t */
  22. #define ZSTD_STATIC_LINKING_ONLY /* ZSTD_parameters */
  23. #include "zstd.h" /* ZSTD_inBuffer, ZSTD_outBuffer, ZSTDLIB_API */
  24. /* === Memory management === */
  25. typedef struct ZSTDMT_CCtx_s ZSTDMT_CCtx;
  26. ZSTDLIB_API ZSTDMT_CCtx* ZSTDMT_createCCtx(unsigned nbThreads);
  27. ZSTDLIB_API ZSTDMT_CCtx* ZSTDMT_createCCtx_advanced(unsigned nbThreads,
  28. ZSTD_customMem cMem);
  29. ZSTDLIB_API size_t ZSTDMT_freeCCtx(ZSTDMT_CCtx* mtctx);
  30. ZSTDLIB_API size_t ZSTDMT_sizeof_CCtx(ZSTDMT_CCtx* mtctx);
  31. /* === Simple buffer-to-butter one-pass function === */
  32. ZSTDLIB_API size_t ZSTDMT_compressCCtx(ZSTDMT_CCtx* mtctx,
  33. void* dst, size_t dstCapacity,
  34. const void* src, size_t srcSize,
  35. int compressionLevel);
  36. /* === Streaming functions === */
  37. ZSTDLIB_API size_t ZSTDMT_initCStream(ZSTDMT_CCtx* mtctx, int compressionLevel);
  38. ZSTDLIB_API size_t ZSTDMT_resetCStream(ZSTDMT_CCtx* mtctx, unsigned long long pledgedSrcSize); /**< pledgedSrcSize is optional and can be zero == unknown */
  39. ZSTDLIB_API size_t ZSTDMT_compressStream(ZSTDMT_CCtx* mtctx, ZSTD_outBuffer* output, ZSTD_inBuffer* input);
  40. ZSTDLIB_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()) */
  41. ZSTDLIB_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()) */
  42. /* === Advanced functions and parameters === */
  43. #ifndef ZSTDMT_SECTION_SIZE_MIN
  44. # define ZSTDMT_SECTION_SIZE_MIN (1U << 20) /* 1 MB - Minimum size of each compression job */
  45. #endif
  46. ZSTDLIB_API size_t ZSTDMT_compress_advanced(ZSTDMT_CCtx* mtctx,
  47. void* dst, size_t dstCapacity,
  48. const void* src, size_t srcSize,
  49. const ZSTD_CDict* cdict,
  50. ZSTD_parameters const params,
  51. unsigned overlapLog);
  52. ZSTDLIB_API size_t ZSTDMT_initCStream_advanced(ZSTDMT_CCtx* mtctx,
  53. const void* dict, size_t dictSize, /* dict can be released after init, a local copy is preserved within zcs */
  54. ZSTD_parameters params,
  55. unsigned long long pledgedSrcSize); /* pledgedSrcSize is optional and can be zero == unknown */
  56. ZSTDLIB_API size_t ZSTDMT_initCStream_usingCDict(ZSTDMT_CCtx* mtctx,
  57. const ZSTD_CDict* cdict,
  58. ZSTD_frameParameters fparams,
  59. unsigned long long pledgedSrcSize); /* note : zero means empty */
  60. /* ZSTDMT_parameter :
  61. * List of parameters that can be set using ZSTDMT_setMTCtxParameter() */
  62. typedef enum {
  63. ZSTDMT_p_sectionSize, /* size of input "section". Each section is compressed in parallel. 0 means default, which is dynamically determined within compression functions */
  64. ZSTDMT_p_overlapSectionLog /* Log of overlapped section; 0 == no overlap, 6(default) == use 1/8th of window, >=9 == use full window */
  65. } ZSTDMT_parameter;
  66. /* ZSTDMT_setMTCtxParameter() :
  67. * allow setting individual parameters, one at a time, among a list of enums defined in ZSTDMT_parameter.
  68. * The function must be called typically after ZSTD_createCCtx().
  69. * Parameters not explicitly reset by ZSTDMT_init*() remain the same in consecutive compression sessions.
  70. * @return : 0, or an error code (which can be tested using ZSTD_isError()) */
  71. ZSTDLIB_API size_t ZSTDMT_setMTCtxParameter(ZSTDMT_CCtx* mtctx, ZSTDMT_parameter parameter, unsigned value);
  72. /*! ZSTDMT_compressStream_generic() :
  73. * Combines ZSTDMT_compressStream() with ZSTDMT_flushStream() or ZSTDMT_endStream()
  74. * depending on flush directive.
  75. * @return : minimum amount of data still to be flushed
  76. * 0 if fully flushed
  77. * or an error code */
  78. ZSTDLIB_API size_t ZSTDMT_compressStream_generic(ZSTDMT_CCtx* mtctx,
  79. ZSTD_outBuffer* output,
  80. ZSTD_inBuffer* input,
  81. ZSTD_EndDirective endOp);
  82. /* === Private definitions; never ever use directly === */
  83. size_t ZSTDMT_CCtxParam_setMTCtxParameter(ZSTD_CCtx_params* params, ZSTDMT_parameter parameter, unsigned value);
  84. size_t ZSTDMT_initializeCCtxParameters(ZSTD_CCtx_params* params, unsigned nbThreads);
  85. /*! ZSTDMT_initCStream_internal() :
  86. * Private use only. Init streaming operation.
  87. * expects params to be valid.
  88. * must receive dict, or cdict, or none, but not both.
  89. * @return : 0, or an error code */
  90. size_t ZSTDMT_initCStream_internal(ZSTDMT_CCtx* zcs,
  91. const void* dict, size_t dictSize, ZSTD_dictMode_e dictMode,
  92. const ZSTD_CDict* cdict,
  93. ZSTD_CCtx_params params, unsigned long long pledgedSrcSize);
  94. #if defined (__cplusplus)
  95. }
  96. #endif
  97. #endif /* ZSTDMT_COMPRESS_H */