1 /* 2 bindbc/zstandard/zstd.d 3 4 Translates al dynamic and most static functions from zstd.h 5 6 Licensed under the Boost Software License 7 8 2018 - Laszlo Szeremi 9 */ 10 11 module bindbc.zstandard.zstd; 12 13 enum ZSTD_MAGICNUMBER = 0xFD2FB528; /* v0.8+ */ 14 enum ZSTD_MAGIC_DICTIONARY = 0xEC30A437; /* v0.7+ */ 15 enum ZSTD_MAGIC_SKIPPABLE_START = 0x184D2A50U; 16 enum ZSTD_BLOCKSIZELOG_MAX = 17; 17 enum ZSTD_BLOCKSIZE_MAX = (1<<ZSTD_BLOCKSIZELOG_MAX); /* define, for static allocation */ 18 19 enum ZSTD_nextInputType_e { 20 ZSTDnit_frameHeader, 21 ZSTDnit_blockHeader, 22 ZSTDnit_block, 23 ZSTDnit_lastBlock, 24 ZSTDnit_checksum, 25 ZSTDnit_skippableFrame 26 } 27 version(zstd1_04){ 28 enum ZSTD_EndDirective{ 29 ZSTD_e_continue=0, 30 ZSTD_e_flush=1, 31 ZSTD_e_end=2 32 } 33 } 34 ///Note: Not yet available in 1.3 versions with dynamic linking. 35 enum ZSTD_strategy{ 36 ZSTD_fast=1, 37 ZSTD_dfast=2, 38 ZSTD_greedy=3, 39 ZSTD_lazy=4, 40 ZSTD_lazy2=5, 41 ZSTD_btlazy2=6, 42 ZSTD_btopt=7, 43 ZSTD_btultra=8, 44 ZSTD_btultra2=9 45 } 46 ///Note: Not yet available in 1.3 versions with dynamic linking. 47 enum ZSTD_cParameter{ 48 49 /* compression parameters 50 * Note: When compressing with a ZSTD_CDict these parameters are superseded 51 * by the parameters used to construct the ZSTD_CDict. See ZSTD_CCtx_refCDict() 52 * for more info (superseded-by-cdict). */ 53 ZSTD_c_compressionLevel=100, /* Update all compression parameters according to pre-defined cLevel table 54 * Default level is ZSTD_CLEVEL_DEFAULT==3. 55 * Special: value 0 means default, which is controlled by ZSTD_CLEVEL_DEFAULT. 56 * Note 1 : it's possible to pass a negative compression level. 57 * Note 2 : setting a level sets all default values of other compression parameters */ 58 ZSTD_c_windowLog=101, /* Maximum allowed back-reference distance, expressed as power of 2. 59 * Must be clamped between ZSTD_WINDOWLOG_MIN and ZSTD_WINDOWLOG_MAX. 60 * Special: value 0 means "use default windowLog". 61 * Note: Using a windowLog greater than ZSTD_WINDOWLOG_LIMIT_DEFAULT 62 * requires explicitly allowing such window size at decompression stage if using streaming. */ 63 ZSTD_c_hashLog=102, /* Size of the initial probe table, as a power of 2. 64 * Resulting memory usage is (1 << (hashLog+2)). 65 * Must be clamped between ZSTD_HASHLOG_MIN and ZSTD_HASHLOG_MAX. 66 * Larger tables improve compression ratio of strategies <= dFast, 67 * and improve speed of strategies > dFast. 68 * Special: value 0 means "use default hashLog". */ 69 ZSTD_c_chainLog=103, /* Size of the multi-probe search table, as a power of 2. 70 * Resulting memory usage is (1 << (chainLog+2)). 71 * Must be clamped between ZSTD_CHAINLOG_MIN and ZSTD_CHAINLOG_MAX. 72 * Larger tables result in better and slower compression. 73 * This parameter is useless when using "fast" strategy. 74 * It's still useful when using "dfast" strategy, 75 * in which case it defines a secondary probe table. 76 * Special: value 0 means "use default chainLog". */ 77 ZSTD_c_searchLog=104, /* Number of search attempts, as a power of 2. 78 * More attempts result in better and slower compression. 79 * This parameter is useless when using "fast" and "dFast" strategies. 80 * Special: value 0 means "use default searchLog". */ 81 ZSTD_c_minMatch=105, /* Minimum size of searched matches. 82 * Note that Zstandard can still find matches of smaller size, 83 * it just tweaks its search algorithm to look for this size and larger. 84 * Larger values increase compression and decompression speed, but decrease ratio. 85 * Must be clamped between ZSTD_MINMATCH_MIN and ZSTD_MINMATCH_MAX. 86 * Note that currently, for all strategies < btopt, effective minimum is 4. 87 * , for all strategies > fast, effective maximum is 6. 88 * Special: value 0 means "use default minMatchLength". */ 89 ZSTD_c_targetLength=106, /* Impact of this field depends on strategy. 90 * For strategies btopt, btultra & btultra2: 91 * Length of Match considered "good enough" to stop search. 92 * Larger values make compression stronger, and slower. 93 * For strategy fast: 94 * Distance between match sampling. 95 * Larger values make compression faster, and weaker. 96 * Special: value 0 means "use default targetLength". */ 97 ZSTD_c_strategy=107, /* See ZSTD_strategy enum definition. 98 * The higher the value of selected strategy, the more complex it is, 99 * resulting in stronger and slower compression. 100 * Special: value 0 means "use default strategy". */ 101 102 /* LDM mode parameters */ 103 ZSTD_c_enableLongDistanceMatching=160, /* Enable long distance matching. 104 * This parameter is designed to improve compression ratio 105 * for large inputs, by finding large matches at long distance. 106 * It increases memory usage and window size. 107 * Note: enabling this parameter increases default ZSTD_c_windowLog to 128 MB 108 * except when expressly set to a different value. */ 109 ZSTD_c_ldmHashLog=161, /* Size of the table for long distance matching, as a power of 2. 110 * Larger values increase memory usage and compression ratio, 111 * but decrease compression speed. 112 * Must be clamped between ZSTD_HASHLOG_MIN and ZSTD_HASHLOG_MAX 113 * default: windowlog - 7. 114 * Special: value 0 means "automatically determine hashlog". */ 115 ZSTD_c_ldmMinMatch=162, /* Minimum match size for long distance matcher. 116 * Larger/too small values usually decrease compression ratio. 117 * Must be clamped between ZSTD_LDM_MINMATCH_MIN and ZSTD_LDM_MINMATCH_MAX. 118 * Special: value 0 means "use default value" (default: 64). */ 119 ZSTD_c_ldmBucketSizeLog=163, /* Log size of each bucket in the LDM hash table for collision resolution. 120 * Larger values improve collision resolution but decrease compression speed. 121 * The maximum value is ZSTD_LDM_BUCKETSIZELOG_MAX. 122 * Special: value 0 means "use default value" (default: 3). */ 123 ZSTD_c_ldmHashRateLog=164, /* Frequency of inserting/looking up entries into the LDM hash table. 124 * Must be clamped between 0 and (ZSTD_WINDOWLOG_MAX - ZSTD_HASHLOG_MIN). 125 * Default is MAX(0, (windowLog - ldmHashLog)), optimizing hash table usage. 126 * Larger values improve compression speed. 127 * Deviating far from default value will likely result in a compression ratio decrease. 128 * Special: value 0 means "automatically determine hashRateLog". */ 129 130 /* frame parameters */ 131 ZSTD_c_contentSizeFlag=200, /* Content size will be written into frame header _whenever known_ (default:1) 132 * Content size must be known at the beginning of compression. 133 * This is automatically the case when using ZSTD_compress2(), 134 * For streaming variants, content size must be provided with ZSTD_CCtx_setPledgedSrcSize() */ 135 ZSTD_c_checksumFlag=201, /* A 32-bits checksum of content is written at end of frame (default:0) */ 136 ZSTD_c_dictIDFlag=202, /* When applicable, dictionary's ID is written into frame header (default:1) */ 137 138 /* multi-threading parameters */ 139 /* These parameters are only useful if multi-threading is enabled (compiled with build macro ZSTD_MULTITHREAD). 140 * They return an error otherwise. */ 141 ZSTD_c_nbWorkers=400, /* Select how many threads will be spawned to compress in parallel. 142 * When nbWorkers >= 1, triggers asynchronous mode when used with ZSTD_compressStream*() : 143 * ZSTD_compressStream*() consumes input and flush output if possible, but immediately gives back control to caller, 144 * while compression work is performed in parallel, within worker threads. 145 * (note : a strong exception to this rule is when first invocation of ZSTD_compressStream2() sets ZSTD_e_end : 146 * in which case, ZSTD_compressStream2() delegates to ZSTD_compress2(), which is always a blocking call). 147 * More workers improve speed, but also increase memory usage. 148 * Default value is `0`, aka "single-threaded mode" : no worker is spawned, compression is performed inside Caller's thread, all invocations are blocking */ 149 ZSTD_c_jobSize=401, /* Size of a compression job. This value is enforced only when nbWorkers >= 1. 150 * Each compression job is completed in parallel, so this value can indirectly impact the nb of active threads. 151 * 0 means default, which is dynamically determined based on compression parameters. 152 * Job size must be a minimum of overlap size, or 1 MB, whichever is largest. 153 * The minimum size is automatically and transparently enforced */ 154 ZSTD_c_overlapLog=402, /* Control the overlap size, as a fraction of window size. 155 * The overlap size is an amount of data reloaded from previous job at the beginning of a new job. 156 * It helps preserve compression ratio, while each job is compressed in parallel. 157 * This value is enforced only when nbWorkers >= 1. 158 * Larger values increase compression ratio, but decrease speed. 159 * Possible values range from 0 to 9 : 160 * - 0 means "default" : value will be determined by the library, depending on strategy 161 * - 1 means "no overlap" 162 * - 9 means "full overlap", using a full window size. 163 * Each intermediate rank increases/decreases load size by a factor 2 : 164 * 9: full window; 8: w/2; 7: w/4; 6: w/8; 5:w/16; 4: w/32; 3:w/64; 2:w/128; 1:no overlap; 0:default 165 * default value varies between 6 and 9, depending on strategy */ 166 167 /* note : additional experimental parameters are also available 168 * within the experimental section of the API. 169 * At the time of this writing, they include : 170 * ZSTD_c_rsyncable 171 * ZSTD_c_format 172 * ZSTD_c_forceMaxWindow 173 * ZSTD_c_forceAttachDict 174 * ZSTD_c_literalCompressionMode 175 * Because they are not stable, it's necessary to define ZSTD_STATIC_LINKING_ONLY to access them. 176 * note : never ever use experimentalParam? names directly; 177 * also, the enums values themselves are unstable and can still change. 178 */ 179 ZSTD_c_experimentalParam1=500, 180 ZSTD_c_experimentalParam2=10, 181 ZSTD_c_experimentalParam3=1000, 182 ZSTD_c_experimentalParam4=1001, 183 ZSTD_c_experimentalParam5=1002, 184 } 185 ///NOTE: 1.4 only 186 enum ZSTD_ResetDirective{ 187 ZSTD_reset_session_only = 1, 188 ZSTD_reset_parameters = 2, 189 ZSTD_reset_session_and_parameters = 3 190 } 191 struct ZSTD_bounds{ 192 size_t error; 193 int lowerBound; 194 int upperBound; 195 } 196 enum ZSTD_CONTENTSIZE_UNKNOWN = 0UL-1; 197 enum ZSTD_CONTENTSIZE_ERROR = 0UL-2; 198 struct ZSTD_CCtx_s{} 199 struct ZSTD_DCtx_s{} 200 struct ZSTD_CDict_s{} 201 struct ZSTD_DDict_s{} 202 alias ZSTD_CCtx = ZSTD_CCtx_s; 203 alias ZSTD_DCtx = ZSTD_DCtx_s; 204 alias ZSTD_CDict = ZSTD_CDict_s; 205 alias ZSTD_DDict = ZSTD_DDict_s; 206 struct ZSTD_inBuffer_s { 207 const(void)* src; /**< start of input buffer */ 208 size_t size; /**< size of input buffer */ 209 size_t pos; /**< position where reading stopped. Will be updated. Necessarily 0 <= pos <= size */ 210 } 211 alias ZSTD_inBuffer = ZSTD_inBuffer_s; 212 struct ZSTD_outBuffer_s { 213 void* dst; /**< start of output buffer */ 214 size_t size; /**< size of output buffer */ 215 size_t pos; /**< position where writing stopped. Will be updated. Necessarily 0 <= pos <= size */ 216 } 217 alias ZSTD_outBuffer = ZSTD_outBuffer_s; 218 alias ZSTD_CStream = ZSTD_CCtx; 219 alias ZSTD_DStream = ZSTD_DCtx; 220 221 /** 222 * Helper function, found in the original API as a precompiler macro. 223 */ 224 @nogc nothrow size_t ZSTD_COMPRESSBOUND(size_t srcSize){ 225 return ((srcSize) + ((srcSize)>>8) + (((srcSize) < (128<<10)) ? (((128<<10) - (srcSize)) >> 11) /* margin, from 64 to 0 */ : 0)); 226 } 227 228 version(BindZSTD_Static){ 229 extern(C) @nogc nothrow: 230 uint ZSTD_versionNumber(); 231 const(char)* ZSTD_versionString(); 232 size_t ZSTD_compress(void* dst, size_t dstCapacity, const(void)* src, size_t srcSize, int compressionLevel); 233 size_t ZSTD_decompress(void* dst, size_t dstCapacity, const(void)* src, size_t compressedSize); 234 ulong ZSTD_getFrameContentSize(const(void)* src, size_t srcSize); 235 ulong ZSTD_getDecompressedSize(const(void)* src, size_t srcSize); 236 size_t ZSTD_compressBound(size_t srcSize); 237 uint ZSTD_isError(size_t code); 238 const(char)* ZSTD_getErrorName(size_t code); 239 int ZSTD_maxCLevel(); 240 ZSTD_CCtx* ZSTD_createCCtx(); 241 size_t ZSTD_freeCCtx(ZSTD_CCtx* cctx); 242 size_t ZSTD_compressCCtx(ZSTD_CCtx* ctx, void* dst, size_t dstCapacity, const(void)* src, size_t srcSize, 243 int compressionLevel); 244 ZSTD_DCtx* ZSTD_createDCtx(); 245 size_t ZSTD_freeDCtx(ZSTD_DCtx* dctx); 246 size_t ZSTD_decompressDCtx(ZSTD_DCtx* ctx, void* dst, size_t dstCapacity, const(void)* src, size_t srcSize); 247 size_t ZSTD_compress_usingDict(ZSTD_CCtx* ctx, void* dst, size_t dstCapacity, const(void)* src, size_t srcSize, 248 const(void)* dict,size_t dictSize, int compressionLevel); 249 size_t ZSTD_decompress_usingDict(ZSTD_DCtx* dctx, void* dst, size_t dstCapacity, const(void)* src, size_t srcSize, 250 const(void)* dict,size_t dictSize); 251 ZSTD_CDict* ZSTD_createCDict(const(void)* dictBuffer, size_t dictSize, int compressionLevel); 252 size_t ZSTD_freeCDict(ZSTD_CDict* CDict); 253 size_t ZSTD_compress_usingCDict(ZSTD_CCtx* cctx, void* dst, size_t dstCapacity, const(void)* src, size_t srcSize, 254 const(ZSTD_CDict)* cdict); 255 ZSTD_DDict* ZSTD_createDDict(const(void)* dictBuffer, size_t dictSize); 256 size_t ZSTD_freeDDict(ZSTD_DDict* ddict); 257 size_t ZSTD_decompress_usingDDict(ZSTD_DCtx* dctx, void* dst, size_t dstCapacity, const(void)* src, size_t srcSize, 258 const(ZSTD_DDict)* ddict); 259 ZSTD_CStream* ZSTD_createCStream(); 260 size_t ZSTD_freeCStream(ZSTD_CStream* zcs); 261 size_t ZSTD_initCStream(ZSTD_CStream* zcs, int compressionLevel); 262 size_t ZSTD_compressStream(ZSTD_CStream* zcs, ZSTD_outBuffer* output, ZSTD_inBuffer* input); 263 size_t ZSTD_flushStream(ZSTD_CStream* zcs, ZSTD_outBuffer* output); 264 size_t ZSTD_endStream(ZSTD_CStream* zcs, ZSTD_outBuffer* output); 265 size_t ZSTD_CStreamInSize(); 266 size_t ZSTD_CStreamOutSize(); 267 ZSTD_DStream* ZSTD_createDStream(); 268 size_t ZSTD_freeDStream(ZSTD_DStream* zds); 269 size_t ZSTD_initDStream(ZSTD_DStream* zds); 270 size_t ZSTD_decompressStream(ZSTD_DStream* zds, ZSTD_outBuffer* output, ZSTD_inBuffer* input); 271 size_t ZSTD_DStreamInSize(); 272 size_t ZSTD_DStreamOutSize(); 273 version(zstd1_04){ 274 size_t ZSTD_compressStream2(ZSTD_CCtx* cctx, ZSTD_outBuffer* output, ZSTD_inBuffer* input, ZSTD_EndDirective endOp); 275 276 ZSTD_bounds ZSTD_cParam_getBounds(ZSTD_cParameter cParam); 277 size_t ZSTD_CCtx_setParameter(ZSTD_CCtx* cctx, ZSTD_cParameter param, int value); 278 size_t ZSTD_CCtx_setPledgedSrcSize(ZSTD_CCtx* cctx, ulong pledgedSrcSize); 279 size_t ZSTD_CCtx_reset(ZSTD_CCtx* cctx, ZSTD_ResetDirective reset); 280 size_t ZSTD_compress2( ZSTD_CCtx* cctx, void* dst, size_t dstCapacity, const(void)* src, size_t srcSize); 281 uint ZSTD_getDictID_fromDict(const(void)* dict, size_t dictSize); 282 uint ZSTD_getDictID_fromDDict(const(ZSTD_DDict)* ddict); 283 size_t ZSTD_CCtx_loadDictionary(ZSTD_CCtx* cctx, const(void)* dict, size_t dictSize); 284 size_t ZSTD_DCtx_reset(ZSTD_DCtx* dctx, ZSTD_ResetDirective reset); 285 size_t ZSTD_CCtx_refCDict(ZSTD_CCtx* cctx, const(ZSTD_CDict)* cdict); 286 size_t ZSTD_CCtx_refPrefix(ZSTD_CCtx* cctx, const(void*) prefix, size_t prefixSize); 287 size_t ZSTD_DCtx_loadDictionary(ZSTD_DCtx* dctx, const(void)* dict, size_t dictSize); 288 size_t ZSTD_DCtx_refDDict(ZSTD_DCtx* dctx, const(ZSTD_DDict)* ddict); 289 size_t ZSTD_DCtx_refPrefix(ZSTD_DCtx* dctx, const(void)* prefix, size_t prefixSize); 290 size_t ZSTD_sizeof_CCtx(const ZSTD_CCtx* cctx); 291 size_t ZSTD_sizeof_DCtx(const ZSTD_DCtx* dctx); 292 size_t ZSTD_sizeof_CStream(const ZSTD_CStream* zcs); 293 size_t ZSTD_sizeof_DStream(const ZSTD_DStream* zds); 294 size_t ZSTD_sizeof_CDict(const ZSTD_CDict* cdict); 295 size_t ZSTD_sizeof_DDict(const ZSTD_DDict* ddict); 296 } 297 298 //static linkage only functions begin here 299 int ZSTD_minCLevel(); 300 enum ZSTD_WINDOWLOG_MAX_32 = 30; 301 enum ZSTD_WINDOWLOG_MAX_64 = 31; 302 enum ZSTD_WINDOWLOG_MAX = (cast(uint)size_t.sizeof == 4 ? ZSTD_WINDOWLOG_MAX_32 : ZSTD_WINDOWLOG_MAX_64); 303 enum ZSTD_WINDOWLOG_MIN = 10; 304 enum ZSTD_HASHLOG_MAX = ((ZSTD_WINDOWLOG_MAX < 30) ? ZSTD_WINDOWLOG_MAX : 30); 305 enum ZSTD_HASHLOG_MIN = 6; 306 enum ZSTD_CHAINLOG_MAX_32 = 29; 307 enum ZSTD_CHAINLOG_MAX_64 = 30; 308 enum ZSTD_CHAINLOG_MAX = (cast(uint)size_t.sizeof == 4 ? ZSTD_CHAINLOG_MAX_32 : ZSTD_CHAINLOG_MAX_64); 309 enum ZSTD_CHAINLOG_MIN = ZSTD_HASHLOG_MIN; 310 enum ZSTD_HASHLOG3_MAX = 17; 311 enum ZSTD_SEARCHLOG_MAX = (ZSTD_WINDOWLOG_MAX-1); 312 enum ZSTD_SEARCHLOG_MIN = 1; 313 enum ZSTD_SEARCHLENGTH_MAX = 7; /* only for ZSTD_fast, other strategies are limited to 6 */ 314 enum ZSTD_SEARCHLENGTH_MIN = 3; /* only for ZSTD_btopt, other strategies are limited to 4 */ 315 enum ZSTD_TARGETLENGTH_MAX = ZSTD_BLOCKSIZE_MAX; 316 enum ZSTD_TARGETLENGTH_MIN = 0; /* note : comparing this constant to an unsigned results in a tautological test */ 317 enum ZSTD_LDM_MINMATCH_MAX = 4096; 318 enum ZSTD_LDM_MINMATCH_MIN = 4; 319 enum ZSTD_LDM_BUCKETSIZELOG_MAX = 8; 320 enum ZSTD_FRAMEHEADERSIZE_PREFIX = 5; /* minimum input size to know frame header size */ 321 enum ZSTD_FRAMEHEADERSIZE_MIN = 6; 322 enum ZSTD_FRAMEHEADERSIZE_MAX = 18; /* for static allocation */ 323 static const size_t ZSTD_frameHeaderSize_prefix = ZSTD_FRAMEHEADERSIZE_PREFIX; 324 static const size_t ZSTD_frameHeaderSize_min = ZSTD_FRAMEHEADERSIZE_MIN; 325 static const size_t ZSTD_frameHeaderSize_max = ZSTD_FRAMEHEADERSIZE_MAX; 326 static const size_t ZSTD_skippableHeaderSize = 8; /* magic number + skippable frame length */ 327 328 struct ZSTD_compressionParameters{ 329 uint windowLog; /**< largest match distance : larger == more compression, more memory needed during decompression */ 330 uint chainLog; /**< fully searched segment : larger == more compression, slower, more memory (useless for fast) */ 331 uint hashLog; /**< dispatch table : larger == faster, more memory */ 332 uint searchLog; /**< nb of searches : larger == more compression, slower */ 333 uint searchLength; /**< match length searched : larger == faster decompression, sometimes less compression */ 334 uint targetLength; /**< acceptable match size for optimal parser (only) : larger == more compression, slower */ 335 ZSTD_strategy strategy; 336 } 337 struct ZSTD_frameParameters{ 338 uint contentSizeFlag; /**< 1: content size will be in frame header (when known) */ 339 uint checksumFlag; /**< 1: generate a 32-bits checksum at end of frame, for error detection */ 340 uint noDictIDFlag; /**< 1: no dictID will be saved into frame header (if dictionary compression) */ 341 } 342 struct ZSTD_parameters{ 343 ZSTD_compressionParameters cParams; 344 ZSTD_frameParameters fParams; 345 } 346 struct ZSTD_CCtx_params_s{ 347 348 } 349 alias ZSTD_CCtx_params = ZSTD_CCtx_params_s; 350 enum ZSTD_dictContentType_e { 351 ZSTD_dct_auto=0, /* dictionary is "full" when starting with ZSTD_MAGIC_DICTIONARY, otherwise it is "rawContent" */ 352 ZSTD_dct_rawContent, /* ensures dictionary is always loaded as rawContent, even if it starts with ZSTD_MAGIC_DICTIONARY */ 353 ZSTD_dct_fullDict /* refuses to load a dictionary if it does not respect Zstandard's specification */ 354 } 355 enum ZSTD_dictLoadMethod_e { 356 ZSTD_dlm_byCopy = 0, /**< Copy dictionary content internally */ 357 ZSTD_dlm_byRef, /**< Reference dictionary content -- the dictionary buffer must outlive its users. */ 358 } 359 size_t ZSTD_findFrameCompressedSize(const(void)* src, size_t srcSize); 360 ulong ZSTD_findDecompressedSize(const(void)* src, size_t srcSize); 361 size_t ZSTD_frameHeaderSize(const(void)* src, size_t srcSize); 362 //size_t ZSTD_sizeof_CCtx(const(ZSTD_CCtx)* cctx); 363 //size_t ZSTD_sizeof_DCtx(const(ZSTD_DCtx)* dctx); 364 //size_t ZSTD_sizeof_CStream(const(ZSTD_CStream)* zcs); 365 //size_t ZSTD_sizeof_DStream(const(ZSTD_DStream)* zds); 366 //size_t ZSTD_sizeof_CDict(const(ZSTD_CDict)* cdict); 367 //size_t ZSTD_sizeof_DDict(const(ZSTD_DDict)* ddict); 368 size_t ZSTD_estimateCCtxSize(int compressionLevel); 369 size_t ZSTD_estimateCCtxSize_usingCParams(ZSTD_compressionParameters cParams); 370 size_t ZSTD_estimateCCtxSize_usingCCtxParams(const(ZSTD_CCtx_params)* params); 371 size_t ZSTD_estimateDCtxSize(); 372 size_t ZSTD_estimateCStreamSize(int compressionLevel); 373 size_t ZSTD_estimateCStreamSize_usingCParams(ZSTD_compressionParameters cParams); 374 size_t ZSTD_estimateCStreamSize_usingCCtxParams(const(ZSTD_CCtx_params)* params); 375 size_t ZSTD_estimateDStreamSize(size_t windowSize); 376 size_t ZSTD_estimateDStreamSize_fromFrame(const(void)* src, size_t srcSize); 377 size_t ZSTD_estimateCDictSize(size_t dictSize, int compressionLevel); 378 size_t ZSTD_estimateCDictSize_advanced(size_t dictSize, ZSTD_compressionParameters cParams, ZSTD_dictLoadMethod_e dictLoadMethod); 379 size_t ZSTD_estimateDDictSize(size_t dictSize, ZSTD_dictLoadMethod_e dictLoadMethod); 380 ZSTD_CCtx* ZSTD_initStaticCCtx(void* workspace, size_t workspaceSize); 381 ZSTD_CStream* ZSTD_initStaticCStream(void* workspace, size_t workspaceSize); 382 ZSTD_DCtx* ZSTD_initStaticDCtx(void* workspace, size_t workspaceSize); 383 ZSTD_DStream* ZSTD_initStaticDStream(void* workspace, size_t workspaceSize); 384 const(ZSTD_CDict)* ZSTD_initStaticCDict(void* workspace, size_t workspaceSize, const(void)* dict, size_t dictSize, 385 ZSTD_dictLoadMethod_e dictLoadMethod, ZSTD_dictContentType_e dictContentType, ZSTD_compressionParameters cParams); 386 const(ZSTD_DDict)* ZSTD_initStaticDDict(void* workspace, size_t workspaceSize, const (void)* dict, size_t dictSize, 387 ZSTD_dictLoadMethod_e dictLoadMethod, ZSTD_dictContentType_e dictContentType); 388 alias ZSTD_allocFunction = void* function(void* opaque, size_t size); 389 alias ZSTD_freeFunction = void function(void* opaque, void* address); 390 struct ZSTD_customMem { 391 ZSTD_allocFunction customAlloc; 392 ZSTD_freeFunction customFree; 393 void* opaque; 394 } 395 static const ZSTD_customMem ZSTD_defaultCMem = ZSTD_customMem(null, null, null); 396 ZSTD_CCtx* ZSTD_createCCtx_advanced(ZSTD_customMem customMem); 397 ZSTD_CStream* ZSTD_createCStream_advanced(ZSTD_customMem customMem); 398 ZSTD_DCtx* ZSTD_createDCtx_advanced(ZSTD_customMem customMem); 399 ZSTD_DStream* ZSTD_createDStream_advanced(ZSTD_customMem customMem); 400 ZSTD_CDict* ZSTD_createCDict_advanced(const(void)* dict, size_t dictSize, ZSTD_dictLoadMethod_e dictLoadMethod, 401 ZSTD_dictContentType_e dictContentType, ZSTD_compressionParameters cParams, ZSTD_customMem customMem); 402 ZSTD_DDict* ZSTD_createDDict_advanced(const(void)* dict, size_t dictSize, ZSTD_dictLoadMethod_e dictLoadMethod, 403 ZSTD_dictContentType_e dictContentType, ZSTD_customMem customMem); 404 ZSTD_CDict* ZSTD_createCDict_byReference(const(void)* dictBuffer, size_t dictSize, int compressionLevel); 405 ZSTD_compressionParameters ZSTD_getCParams(int compressionLevel, ulong estimatedSrcSize, size_t dictSize); 406 ZSTD_parameters ZSTD_getParams(int compressionLevel, ulong estimatedSrcSize, size_t dictSize); 407 size_t ZSTD_checkCParams(ZSTD_compressionParameters params); 408 ZSTD_compressionParameters ZSTD_adjustCParams(ZSTD_compressionParameters cPar, ulong srcSize, size_t dictSize); 409 size_t ZSTD_compress_advanced (ZSTD_CCtx* cctx, void* dst, size_t dstCapacity, const(void)* src, size_t srcSize, 410 const(void)* dict, size_t dictSize, ZSTD_parameters params); 411 size_t ZSTD_compress_usingCDict_advanced(ZSTD_CCtx* cctx, void* dst, size_t dstCapacity, const(void)* src, size_t srcSize, 412 const(ZSTD_CDict)* cdict, ZSTD_frameParameters fParams); 413 uint ZSTD_isFrame(const(void)* buffer, size_t size); 414 ZSTD_DDict* ZSTD_createDDict_byReference(const(void)* dictBuffer, size_t dictSize); 415 //uint ZSTD_getDictID_fromDict(const(void)* dict, size_t dictSize); 416 //uint ZSTD_getDictID_fromDDict(const(ZSTD_DDict)* ddict); 417 uint ZSTD_getDictID_fromFrame(const(void)* src, size_t srcSize); 418 size_t ZSTD_initCStream_srcSize(ZSTD_CStream* zcs, int compressionLevel, ulong pledgedSrcSize); 419 size_t ZSTD_initCStream_usingDict(ZSTD_CStream* zcs, const(void)* dict, size_t dictSize, int compressionLevel); 420 size_t ZSTD_initCStream_advanced(ZSTD_CStream* zcs, const(void)* dict, size_t dictSize, ZSTD_parameters params, 421 ulong pledgedSrcSize); 422 size_t ZSTD_initCStream_usingCDict(ZSTD_CStream* zcs, const(ZSTD_CDict)* cdict); 423 size_t ZSTD_initCStream_usingCDict_advanced(ZSTD_CStream* zcs, const(ZSTD_CDict)* cdict, ZSTD_frameParameters fParams, 424 ulong pledgedSrcSize); 425 size_t ZSTD_resetCStream(ZSTD_CStream* zcs, ulong pledgedSrcSize); 426 struct ZSTD_frameProgression{ 427 ulong ingested; /* nb input bytes read and buffered */ 428 ulong consumed; /* nb input bytes actually compressed */ 429 ulong produced; /* nb of compressed bytes generated and buffered */ 430 ulong flushed; /* nb of compressed bytes flushed : not provided; can be tracked from caller side */ 431 uint currentJobID; /* MT only : latest started job nb */ 432 uint nbActiveWorkers; /* MT only : nb of workers actively compressing at probe time */ 433 } 434 ZSTD_frameProgression ZSTD_getFrameProgression(const(ZSTD_CCtx)* cctx); 435 size_t ZSTD_toFlushNow(ZSTD_CCtx* cctx); 436 enum ZSTD_DStreamParameter_e{ 437 DStream_p_maxWindowSize 438 } 439 size_t ZSTD_setDStreamParameter(ZSTD_DStream* zds, ZSTD_DStreamParameter_e paramType, uint paramValue); /* obsolete : this API will be removed in a future version */ 440 size_t ZSTD_initDStream_usingDict(ZSTD_DStream* zds, const(void)* dict, size_t dictSize); /**< note: no dictionary will be used if dict == NULL or dictSize < 8 */ 441 size_t ZSTD_initDStream_usingDDict(ZSTD_DStream* zds, const(ZSTD_DDict)* ddict); /**< note : ddict is referenced, it must outlive decompression session */ 442 size_t ZSTD_resetDStream(ZSTD_DStream* zds); /**< re-use decompression parameters from previous init; saves dictionary loading */ 443 size_t ZSTD_compressBegin(ZSTD_CCtx* cctx, int compressionLevel); 444 size_t ZSTD_compressBegin_usingDict(ZSTD_CCtx* cctx, const(void)* dict, size_t dictSize, int compressionLevel); 445 size_t ZSTD_compressBegin_advanced(ZSTD_CCtx* cctx, const(void)* dict, size_t dictSize, ZSTD_parameters params, 446 ulong pledgedSrcSize); /**< pledgedSrcSize : If srcSize is not known at init time, use ZSTD_CONTENTSIZE_UNKNOWN */ 447 size_t ZSTD_compressBegin_usingCDict(ZSTD_CCtx* cctx, const ZSTD_CDict* cdict); /**< note: fails if cdict==NULL */ 448 size_t ZSTD_compressBegin_usingCDict_advanced(const(ZSTD_CCtx)* cctx, const ZSTD_CDict* cdict, const ZSTD_frameParameters 449 fParams, const ulong pledgedSrcSize); /* compression parameters are already set within cdict. pledgedSrcSize must be correct. If srcSize is not known, use macro ZSTD_CONTENTSIZE_UNKNOWN */ 450 size_t ZSTD_copyCCtx(ZSTD_CCtx* cctx, const ZSTD_CCtx* preparedCCtx, ulong pledgedSrcSize); /**< note: if pledgedSrcSize is not known, use ZSTD_CONTENTSIZE_UNKNOWN */ 451 size_t ZSTD_compressContinue(ZSTD_CCtx* cctx, void* dst, size_t dstCapacity, const(void)* src, size_t srcSize); 452 size_t ZSTD_compressEnd(ZSTD_CCtx* cctx, void* dst, size_t dstCapacity, const(void)* src, size_t srcSize); 453 enum ZSTD_frameType_e { ZSTD_frame, ZSTD_skippableFrame } 454 struct ZSTD_frameHeader{ 455 ulong frameContentSize; /* if == ZSTD_CONTENTSIZE_UNKNOWN, it means this field is not available. 0 means "empty" */ 456 ulong windowSize; /* can be very large, up to <= frameContentSize */ 457 uint blockSizeMax; 458 ZSTD_frameType_e frameType; /* if == ZSTD_skippableFrame, frameContentSize is the size of skippable content */ 459 uint headerSize; 460 uint dictID; 461 uint checksumFlag; 462 } 463 size_t ZSTD_getFrameHeader(ZSTD_frameHeader* zfhPtr, const(void)* src, size_t srcSize); /**< doesn't consume input */ 464 size_t ZSTD_decodingBufferSize_min(ulong windowSize, ulong frameContentSize); /**< when frame content size is not known, pass in frameContentSize == ZSTD_CONTENTSIZE_UNKNOWN */ 465 size_t ZSTD_decompressBegin(ZSTD_DCtx* dctx); 466 size_t ZSTD_decompressBegin_usingDict(ZSTD_DCtx* dctx, const(void)* dict, size_t dictSize); 467 size_t ZSTD_decompressBegin_usingDDict(ZSTD_DCtx* dctx, const(ZSTD_DDict)* ddict); 468 size_t ZSTD_nextSrcSizeToDecompress(ZSTD_DCtx* dctx); 469 size_t ZSTD_decompressContinue(ZSTD_DCtx* dctx, void* dst, size_t dstCapacity, const(void)* src, size_t srcSize); 470 void ZSTD_copyDCtx(ZSTD_DCtx* dctx, const(ZSTD_DCtx)* preparedDCtx); 471 enum ZSTD_nextInputType_e{ 472 ZSTDnit_frameHeader, 473 ZSTDnit_blockHeader, 474 ZSTDnit_block, 475 ZSTDnit_lastBlock, 476 ZSTDnit_checksum, 477 ZSTDnit_skippableFrame 478 } 479 ZSTD_nextInputType_e ZSTD_nextInputType(ZSTD_DCtx* dctx); 480 //Section under new advanced API is not supported at the moment. 481 }else{ 482 extern(C) @nogc nothrow { 483 alias pZSTD_versionNumber = uint function(); 484 alias pZSTD_versionString = const(char)* function(); 485 alias pZSTD_compress = size_t function(void* dst, size_t dstCapacity, const(void)* src, size_t srcSize, 486 int compressionLevel); 487 alias pZSTD_decompress = size_t function(void* dst, size_t dstCapacity, const(void)* src, size_t compressedSize); 488 alias pZSTD_getFrameContentSize = ulong function(const(void)* src, size_t srcSize); 489 alias pZSTD_getDecompressedSize = ulong function(const(void)* src, size_t srcSize); 490 alias pZSTD_compressBound = size_t function(size_t srcSize); 491 alias pZSTD_isError = uint function(size_t code); 492 alias pZSTD_getErrorName = const(char)* function(size_t code); 493 alias pZSTD_maxCLevel = int function(); 494 alias pZSTD_createCCtx = ZSTD_CCtx* function(); 495 alias pZSTD_freeCCtx = size_t function(ZSTD_CCtx* cctx); 496 alias pZSTD_compressCCtx = size_t function(ZSTD_CCtx* ctx, void* dst, size_t dstCapacity, const(void)* src, 497 size_t srcSize, int compressionLevel); 498 alias pZSTD_createDCtx = ZSTD_DCtx* function(); 499 alias pZSTD_freeDCtx = size_t function(ZSTD_DCtx* dctx); 500 alias pZSTD_decompressDCtx = size_t function(ZSTD_DCtx* ctx, void* dst, size_t dstCapacity, const(void)* src, 501 size_t srcSize); 502 alias pZSTD_compress_usingDict = size_t function(ZSTD_CCtx* ctx, void* dst, size_t dstCapacity, const(void)* src, 503 size_t srcSize, const(void)* dict,size_t dictSize, int compressionLevel); 504 alias pZSTD_decompress_usingDict = size_t function(ZSTD_DCtx* dctx, void* dst, size_t dstCapacity, const(void)* src, 505 size_t srcSize, const(void)* dict,size_t dictSize); 506 alias pZSTD_createCDict = ZSTD_CDict* function(const(void)* dictBuffer, size_t dictSize, int compressionLevel); 507 alias pZSTD_freeCDict = size_t function(ZSTD_CDict* CDict); 508 alias pZSTD_compress_usingCDict = size_t function(ZSTD_CCtx* cctx, void* dst, size_t dstCapacity, const(void)* src, 509 size_t srcSize, const(ZSTD_CDict)* cdict); 510 alias pZSTD_createDDict = ZSTD_DDict* function(const(void)* dictBuffer, size_t dictSize); 511 alias pZSTD_freeDDict = size_t function(ZSTD_DDict* ddict); 512 alias pZSTD_decompress_usingDDict = size_t function(ZSTD_DCtx* dctx, void* dst, size_t dstCapacity, const(void)* src, 513 size_t srcSize, const(ZSTD_DDict)* ddict); 514 alias pZSTD_createCStream = ZSTD_CStream* function(); 515 alias pZSTD_freeCStream = size_t function(ZSTD_CStream* zcs); 516 alias pZSTD_initCStream = size_t function(ZSTD_CStream* zcs, int compressionLevel); 517 alias pZSTD_compressStream = size_t function(ZSTD_CStream* zcs, ZSTD_outBuffer* output, ZSTD_inBuffer* input); 518 alias pZSTD_flushStream = size_t function(ZSTD_CStream* zcs, ZSTD_outBuffer* output); 519 alias pZSTD_endStream = size_t function(ZSTD_CStream* zcs, ZSTD_outBuffer* output); 520 alias pZSTD_CStreamInSize = size_t function(); 521 alias pZSTD_CStreamOutSize = size_t function(); 522 alias pZSTD_createDStream = ZSTD_DStream* function(); 523 alias pZSTD_freeDStream = size_t function(ZSTD_DStream* zds); 524 alias pZSTD_initDStream = size_t function(ZSTD_DStream* zds); 525 alias pZSTD_decompressStream = size_t function(ZSTD_DStream* zds, ZSTD_outBuffer* output, ZSTD_inBuffer* input); 526 alias pZSTD_DStreamInSize = size_t function(); 527 alias pZSTD_DStreamOutSize = size_t function(); 528 version(zstd1_04){ 529 alias pZSTD_compressStream2 = size_t function(ZSTD_CCtx* cctx, ZSTD_outBuffer* output, ZSTD_inBuffer* input, 530 ZSTD_EndDirective endOp); 531 532 alias pZSTD_cParam_getBounds = ZSTD_bounds function(ZSTD_cParameter cParam); 533 alias pZSTD_CCtx_setParameter = size_t function(ZSTD_CCtx* cctx, ZSTD_cParameter param, int value); 534 alias pZSTD_CCtx_setPledgedSrcSize = size_t function(ZSTD_CCtx* cctx, ulong pledgedSrcSize); 535 alias pZSTD_CCtx_reset = size_t function(ZSTD_CCtx* cctx, ZSTD_ResetDirective reset); 536 alias pZSTD_compress2 = size_t function( ZSTD_CCtx* cctx, void* dst, size_t dstCapacity, const(void)* src, size_t srcSize); 537 alias pZSTD_getDictID_fromDict = uint function(const(void)* dict, size_t dictSize); 538 alias pZSTD_getDictID_fromDDict = uint function(const(ZSTD_DDict)* ddict); 539 alias pZSTD_CCtx_loadDictionary = size_t function(ZSTD_CCtx* cctx, const(void)* dict, size_t dictSize); 540 alias pZSTD_DCtx_reset = size_t function(ZSTD_DCtx* dctx, ZSTD_ResetDirective reset); 541 alias pZSTD_CCtx_refCDict = size_t function(ZSTD_CCtx* cctx, const(ZSTD_CDict)* cdict); 542 alias pZSTD_CCtx_refPrefix = size_t function(ZSTD_CCtx* cctx, const(void*) prefix, size_t prefixSize); 543 alias pZSTD_DCtx_loadDictionary = size_t function(ZSTD_DCtx* dctx, const(void)* dict, size_t dictSize); 544 alias pZSTD_DCtx_refDDict = size_t function(ZSTD_DCtx* dctx, const(ZSTD_DDict)* ddict); 545 alias pZSTD_DCtx_refPrefix = size_t function(ZSTD_DCtx* dctx, const(void)* prefix, size_t prefixSize); 546 alias pZSTD_sizeof_CCtx = size_t function(const ZSTD_CCtx* cctx); 547 alias pZSTD_sizeof_DCtx = size_t function(const ZSTD_DCtx* dctx); 548 alias pZSTD_sizeof_CStream = size_t function(const ZSTD_CStream* zcs); 549 alias pZSTD_sizeof_DStream = size_t function(const ZSTD_DStream* zds); 550 alias pZSTD_sizeof_CDict = size_t function(const ZSTD_CDict* cdict); 551 alias pZSTD_sizeof_DDict = size_t function(const ZSTD_DDict* ddict); 552 } 553 } 554 555 __gshared { 556 pZSTD_versionNumber ZSTD_versionNumber; 557 pZSTD_versionString ZSTD_versionString; 558 pZSTD_compress ZSTD_compress; 559 pZSTD_decompress ZSTD_decompress; 560 pZSTD_getFrameContentSize ZSTD_getFrameContentSize; 561 pZSTD_getDecompressedSize ZSTD_getDecompressedSize; 562 pZSTD_compressBound ZSTD_compressBound; 563 pZSTD_isError ZSTD_isError; 564 pZSTD_getErrorName ZSTD_getErrorName; 565 pZSTD_maxCLevel ZSTD_maxCLevel; 566 pZSTD_createCCtx ZSTD_createCCtx; 567 pZSTD_freeCCtx ZSTD_freeCCtx; 568 pZSTD_compressCCtx ZSTD_compressCCtx; 569 pZSTD_createDCtx ZSTD_createDCtx; 570 pZSTD_freeDCtx ZSTD_freeDCtx; 571 pZSTD_decompressDCtx ZSTD_decompressDCtx; 572 pZSTD_compress_usingDict ZSTD_compress_usingDict; 573 pZSTD_decompress_usingDict ZSTD_decompress_usingDict; 574 pZSTD_createCDict ZSTD_createCDict; 575 pZSTD_freeCDict ZSTD_freeCDict; 576 pZSTD_compress_usingCDict ZSTD_compress_usingCDict; 577 pZSTD_createDDict ZSTD_createDDict; 578 pZSTD_freeDDict ZSTD_freeDDict; 579 pZSTD_decompress_usingDDict ZSTD_decompress_usingDDict; 580 pZSTD_createCStream ZSTD_createCStream; 581 pZSTD_freeCStream ZSTD_freeCStream; 582 pZSTD_initCStream ZSTD_initCStream; 583 pZSTD_compressStream ZSTD_compressStream; 584 pZSTD_flushStream ZSTD_flushStream; 585 pZSTD_endStream ZSTD_endStream; 586 pZSTD_CStreamInSize ZSTD_CStreamInSize; 587 pZSTD_CStreamOutSize ZSTD_CStreamOutSize; 588 pZSTD_createDStream ZSTD_createDStream; 589 pZSTD_freeDStream ZSTD_freeDStream; 590 pZSTD_initDStream ZSTD_initDStream; 591 pZSTD_decompressStream ZSTD_decompressStream; 592 pZSTD_DStreamInSize ZSTD_DStreamInSize; 593 pZSTD_DStreamOutSize ZSTD_DStreamOutSize; 594 version(zstd1_04){ 595 pZSTD_compressStream2 ZSTD_compressStream2; 596 597 pZSTD_cParam_getBounds ZSTD_cParam_getBounds; 598 pZSTD_CCtx_setParameter ZSTD_CCtx_setParameter; 599 pZSTD_CCtx_setPledgedSrcSize ZSTD_CCtx_setPledgedSrcSize; 600 pZSTD_CCtx_reset ZSTD_CCtx_reset; 601 pZSTD_compress2 ZSTD_compress2; 602 pZSTD_getDictID_fromDict ZSTD_getDictID_fromDict; 603 pZSTD_getDictID_fromDDict ZSTD_getDictID_fromDDict; 604 pZSTD_CCtx_loadDictionary ZSTD_CCtx_loadDictionary; 605 pZSTD_DCtx_reset ZSTD_DCtx_reset; 606 pZSTD_CCtx_refCDict ZSTD_CCtx_refCDict; 607 pZSTD_CCtx_refPrefix ZSTD_CCtx_refPrefix; 608 pZSTD_DCtx_loadDictionary ZSTD_DCtx_loadDictionary; 609 pZSTD_DCtx_refDDict ZSTD_DCtx_refDDict; 610 pZSTD_DCtx_refPrefix ZSTD_DCtx_refPrefix; 611 pZSTD_sizeof_CCtx ZSTD_sizeof_CCtx; 612 pZSTD_sizeof_DCtx ZSTD_sizeof_DCtx; 613 pZSTD_sizeof_CStream ZSTD_sizeof_CStream; 614 pZSTD_sizeof_DStream ZSTD_sizeof_DStream; 615 pZSTD_sizeof_CDict ZSTD_sizeof_CDict; 616 pZSTD_sizeof_DDict ZSTD_sizeof_DDict; 617 } 618 } 619 }