You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

zstdmt_compress.h 6.1KB

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