zstdlib 0.13.0-x86_64-linux
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.yardopts +6 -0
- data/CHANGES.md +107 -0
- data/Gemfile +3 -0
- data/README.md +107 -0
- data/Rakefile +59 -0
- data/ext/zstdlib_c/extconf.rb +59 -0
- data/ext/zstdlib_c/ruby/zlib-2.2/zstdlib.c +4675 -0
- data/ext/zstdlib_c/ruby/zlib-2.3/zstdlib.c +4702 -0
- data/ext/zstdlib_c/ruby/zlib-2.4/zstdlib.c +4859 -0
- data/ext/zstdlib_c/ruby/zlib-2.5/zstdlib.c +4864 -0
- data/ext/zstdlib_c/ruby/zlib-2.6/zstdlib.c +4906 -0
- data/ext/zstdlib_c/ruby/zlib-2.7/zstdlib.c +4895 -0
- data/ext/zstdlib_c/ruby/zlib-3.0/zstdlib.c +4994 -0
- data/ext/zstdlib_c/ruby/zlib-3.1/zstdlib.c +5076 -0
- data/ext/zstdlib_c/ruby/zlib-3.2/zstdlib.c +5090 -0
- data/ext/zstdlib_c/ruby/zlib-3.3/zstdlib.c +5090 -0
- data/ext/zstdlib_c/zlib-1.3.1/adler32.c +164 -0
- data/ext/zstdlib_c/zlib-1.3.1/compress.c +75 -0
- data/ext/zstdlib_c/zlib-1.3.1/crc32.c +1049 -0
- data/ext/zstdlib_c/zlib-1.3.1/crc32.h +9446 -0
- data/ext/zstdlib_c/zlib-1.3.1/deflate.c +2139 -0
- data/ext/zstdlib_c/zlib-1.3.1/deflate.h +377 -0
- data/ext/zstdlib_c/zlib-1.3.1/gzclose.c +23 -0
- data/ext/zstdlib_c/zlib-1.3.1/gzguts.h +214 -0
- data/ext/zstdlib_c/zlib-1.3.1/gzlib.c +582 -0
- data/ext/zstdlib_c/zlib-1.3.1/gzread.c +602 -0
- data/ext/zstdlib_c/zlib-1.3.1/gzwrite.c +631 -0
- data/ext/zstdlib_c/zlib-1.3.1/infback.c +628 -0
- data/ext/zstdlib_c/zlib-1.3.1/inffast.c +320 -0
- data/ext/zstdlib_c/zlib-1.3.1/inffast.h +11 -0
- data/ext/zstdlib_c/zlib-1.3.1/inffixed.h +94 -0
- data/ext/zstdlib_c/zlib-1.3.1/inflate.c +1526 -0
- data/ext/zstdlib_c/zlib-1.3.1/inflate.h +126 -0
- data/ext/zstdlib_c/zlib-1.3.1/inftrees.c +299 -0
- data/ext/zstdlib_c/zlib-1.3.1/inftrees.h +62 -0
- data/ext/zstdlib_c/zlib-1.3.1/trees.c +1117 -0
- data/ext/zstdlib_c/zlib-1.3.1/trees.h +128 -0
- data/ext/zstdlib_c/zlib-1.3.1/uncompr.c +85 -0
- data/ext/zstdlib_c/zlib-1.3.1/zconf.h +543 -0
- data/ext/zstdlib_c/zlib-1.3.1/zlib.h +1938 -0
- data/ext/zstdlib_c/zlib-1.3.1/zutil.c +299 -0
- data/ext/zstdlib_c/zlib-1.3.1/zutil.h +254 -0
- data/ext/zstdlib_c/zlib.mk +14 -0
- data/ext/zstdlib_c/zlibwrapper/zlibwrapper.c +10 -0
- data/ext/zstdlib_c/zlibwrapper.mk +14 -0
- data/ext/zstdlib_c/zstd-1.5.6/lib/common/allocations.h +55 -0
- data/ext/zstdlib_c/zstd-1.5.6/lib/common/bits.h +200 -0
- data/ext/zstdlib_c/zstd-1.5.6/lib/common/bitstream.h +457 -0
- data/ext/zstdlib_c/zstd-1.5.6/lib/common/compiler.h +450 -0
- data/ext/zstdlib_c/zstd-1.5.6/lib/common/cpu.h +249 -0
- data/ext/zstdlib_c/zstd-1.5.6/lib/common/debug.c +30 -0
- data/ext/zstdlib_c/zstd-1.5.6/lib/common/debug.h +116 -0
- data/ext/zstdlib_c/zstd-1.5.6/lib/common/entropy_common.c +340 -0
- data/ext/zstdlib_c/zstd-1.5.6/lib/common/error_private.c +63 -0
- data/ext/zstdlib_c/zstd-1.5.6/lib/common/error_private.h +168 -0
- data/ext/zstdlib_c/zstd-1.5.6/lib/common/fse.h +640 -0
- data/ext/zstdlib_c/zstd-1.5.6/lib/common/fse_decompress.c +313 -0
- data/ext/zstdlib_c/zstd-1.5.6/lib/common/huf.h +286 -0
- data/ext/zstdlib_c/zstd-1.5.6/lib/common/mem.h +426 -0
- data/ext/zstdlib_c/zstd-1.5.6/lib/common/pool.c +371 -0
- data/ext/zstdlib_c/zstd-1.5.6/lib/common/pool.h +90 -0
- data/ext/zstdlib_c/zstd-1.5.6/lib/common/portability_macros.h +158 -0
- data/ext/zstdlib_c/zstd-1.5.6/lib/common/threading.c +182 -0
- data/ext/zstdlib_c/zstd-1.5.6/lib/common/threading.h +150 -0
- data/ext/zstdlib_c/zstd-1.5.6/lib/common/xxhash.c +18 -0
- data/ext/zstdlib_c/zstd-1.5.6/lib/common/xxhash.h +7020 -0
- data/ext/zstdlib_c/zstd-1.5.6/lib/common/zstd_common.c +48 -0
- data/ext/zstdlib_c/zstd-1.5.6/lib/common/zstd_deps.h +111 -0
- data/ext/zstdlib_c/zstd-1.5.6/lib/common/zstd_internal.h +392 -0
- data/ext/zstdlib_c/zstd-1.5.6/lib/common/zstd_trace.h +163 -0
- data/ext/zstdlib_c/zstd-1.5.6/lib/compress/clevels.h +134 -0
- data/ext/zstdlib_c/zstd-1.5.6/lib/compress/fse_compress.c +625 -0
- data/ext/zstdlib_c/zstd-1.5.6/lib/compress/hist.c +181 -0
- data/ext/zstdlib_c/zstd-1.5.6/lib/compress/hist.h +75 -0
- data/ext/zstdlib_c/zstd-1.5.6/lib/compress/huf_compress.c +1464 -0
- data/ext/zstdlib_c/zstd-1.5.6/lib/compress/zstd_compress.c +7153 -0
- data/ext/zstdlib_c/zstd-1.5.6/lib/compress/zstd_compress_internal.h +1534 -0
- data/ext/zstdlib_c/zstd-1.5.6/lib/compress/zstd_compress_literals.c +235 -0
- data/ext/zstdlib_c/zstd-1.5.6/lib/compress/zstd_compress_literals.h +39 -0
- data/ext/zstdlib_c/zstd-1.5.6/lib/compress/zstd_compress_sequences.c +442 -0
- data/ext/zstdlib_c/zstd-1.5.6/lib/compress/zstd_compress_sequences.h +54 -0
- data/ext/zstdlib_c/zstd-1.5.6/lib/compress/zstd_compress_superblock.c +688 -0
- data/ext/zstdlib_c/zstd-1.5.6/lib/compress/zstd_compress_superblock.h +32 -0
- data/ext/zstdlib_c/zstd-1.5.6/lib/compress/zstd_cwksp.h +748 -0
- data/ext/zstdlib_c/zstd-1.5.6/lib/compress/zstd_double_fast.c +770 -0
- data/ext/zstdlib_c/zstd-1.5.6/lib/compress/zstd_double_fast.h +50 -0
- data/ext/zstdlib_c/zstd-1.5.6/lib/compress/zstd_fast.c +968 -0
- data/ext/zstdlib_c/zstd-1.5.6/lib/compress/zstd_fast.h +38 -0
- data/ext/zstdlib_c/zstd-1.5.6/lib/compress/zstd_lazy.c +2199 -0
- data/ext/zstdlib_c/zstd-1.5.6/lib/compress/zstd_lazy.h +202 -0
- data/ext/zstdlib_c/zstd-1.5.6/lib/compress/zstd_ldm.c +730 -0
- data/ext/zstdlib_c/zstd-1.5.6/lib/compress/zstd_ldm.h +117 -0
- data/ext/zstdlib_c/zstd-1.5.6/lib/compress/zstd_ldm_geartab.h +106 -0
- data/ext/zstdlib_c/zstd-1.5.6/lib/compress/zstd_opt.c +1576 -0
- data/ext/zstdlib_c/zstd-1.5.6/lib/compress/zstd_opt.h +80 -0
- data/ext/zstdlib_c/zstd-1.5.6/lib/compress/zstdmt_compress.c +1882 -0
- data/ext/zstdlib_c/zstd-1.5.6/lib/compress/zstdmt_compress.h +113 -0
- data/ext/zstdlib_c/zstd-1.5.6/lib/decompress/huf_decompress.c +1944 -0
- data/ext/zstdlib_c/zstd-1.5.6/lib/decompress/huf_decompress_amd64.S +595 -0
- data/ext/zstdlib_c/zstd-1.5.6/lib/decompress/zstd_ddict.c +244 -0
- data/ext/zstdlib_c/zstd-1.5.6/lib/decompress/zstd_ddict.h +44 -0
- data/ext/zstdlib_c/zstd-1.5.6/lib/decompress/zstd_decompress.c +2407 -0
- data/ext/zstdlib_c/zstd-1.5.6/lib/decompress/zstd_decompress_block.c +2215 -0
- data/ext/zstdlib_c/zstd-1.5.6/lib/decompress/zstd_decompress_block.h +73 -0
- data/ext/zstdlib_c/zstd-1.5.6/lib/decompress/zstd_decompress_internal.h +240 -0
- data/ext/zstdlib_c/zstd-1.5.6/lib/zdict.h +474 -0
- data/ext/zstdlib_c/zstd-1.5.6/lib/zstd.h +3089 -0
- data/ext/zstdlib_c/zstd-1.5.6/lib/zstd_errors.h +114 -0
- data/ext/zstdlib_c/zstd-1.5.6/zlibWrapper/gzclose.c +26 -0
- data/ext/zstdlib_c/zstd-1.5.6/zlibWrapper/gzcompatibility.h +68 -0
- data/ext/zstdlib_c/zstd-1.5.6/zlibWrapper/gzguts.h +229 -0
- data/ext/zstdlib_c/zstd-1.5.6/zlibWrapper/gzlib.c +587 -0
- data/ext/zstdlib_c/zstd-1.5.6/zlibWrapper/gzread.c +637 -0
- data/ext/zstdlib_c/zstd-1.5.6/zlibWrapper/gzwrite.c +631 -0
- data/ext/zstdlib_c/zstd-1.5.6/zlibWrapper/zstd_zlibwrapper.c +1200 -0
- data/ext/zstdlib_c/zstd-1.5.6/zlibWrapper/zstd_zlibwrapper.h +91 -0
- data/ext/zstdlib_c/zstd.mk +15 -0
- data/lib/2.4/zstdlib_c.so +0 -0
- data/lib/2.5/zstdlib_c.so +0 -0
- data/lib/2.6/zstdlib_c.so +0 -0
- data/lib/2.7/zstdlib_c.so +0 -0
- data/lib/3.0/zstdlib_c.so +0 -0
- data/lib/3.1/zstdlib_c.so +0 -0
- data/lib/3.2/zstdlib_c.so +0 -0
- data/lib/3.3/zstdlib_c.so +0 -0
- data/lib/zstdlib.rb +6 -0
- data/test/zstdlib_test.rb +21 -0
- metadata +243 -0
@@ -0,0 +1,244 @@
|
|
1
|
+
/*
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
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
|
+
|
11
|
+
/* zstd_ddict.c :
|
12
|
+
* concentrates all logic that needs to know the internals of ZSTD_DDict object */
|
13
|
+
|
14
|
+
/*-*******************************************************
|
15
|
+
* Dependencies
|
16
|
+
*********************************************************/
|
17
|
+
#include "../common/allocations.h" /* ZSTD_customMalloc, ZSTD_customFree */
|
18
|
+
#include "../common/zstd_deps.h" /* ZSTD_memcpy, ZSTD_memmove, ZSTD_memset */
|
19
|
+
#include "../common/cpu.h" /* bmi2 */
|
20
|
+
#include "../common/mem.h" /* low level memory routines */
|
21
|
+
#define FSE_STATIC_LINKING_ONLY
|
22
|
+
#include "../common/fse.h"
|
23
|
+
#include "../common/huf.h"
|
24
|
+
#include "zstd_decompress_internal.h"
|
25
|
+
#include "zstd_ddict.h"
|
26
|
+
|
27
|
+
#if defined(ZSTD_LEGACY_SUPPORT) && (ZSTD_LEGACY_SUPPORT>=1)
|
28
|
+
# include "../legacy/zstd_legacy.h"
|
29
|
+
#endif
|
30
|
+
|
31
|
+
|
32
|
+
|
33
|
+
/*-*******************************************************
|
34
|
+
* Types
|
35
|
+
*********************************************************/
|
36
|
+
struct ZSTD_DDict_s {
|
37
|
+
void* dictBuffer;
|
38
|
+
const void* dictContent;
|
39
|
+
size_t dictSize;
|
40
|
+
ZSTD_entropyDTables_t entropy;
|
41
|
+
U32 dictID;
|
42
|
+
U32 entropyPresent;
|
43
|
+
ZSTD_customMem cMem;
|
44
|
+
}; /* typedef'd to ZSTD_DDict within "zstd.h" */
|
45
|
+
|
46
|
+
const void* ZSTD_DDict_dictContent(const ZSTD_DDict* ddict)
|
47
|
+
{
|
48
|
+
assert(ddict != NULL);
|
49
|
+
return ddict->dictContent;
|
50
|
+
}
|
51
|
+
|
52
|
+
size_t ZSTD_DDict_dictSize(const ZSTD_DDict* ddict)
|
53
|
+
{
|
54
|
+
assert(ddict != NULL);
|
55
|
+
return ddict->dictSize;
|
56
|
+
}
|
57
|
+
|
58
|
+
void ZSTD_copyDDictParameters(ZSTD_DCtx* dctx, const ZSTD_DDict* ddict)
|
59
|
+
{
|
60
|
+
DEBUGLOG(4, "ZSTD_copyDDictParameters");
|
61
|
+
assert(dctx != NULL);
|
62
|
+
assert(ddict != NULL);
|
63
|
+
dctx->dictID = ddict->dictID;
|
64
|
+
dctx->prefixStart = ddict->dictContent;
|
65
|
+
dctx->virtualStart = ddict->dictContent;
|
66
|
+
dctx->dictEnd = (const BYTE*)ddict->dictContent + ddict->dictSize;
|
67
|
+
dctx->previousDstEnd = dctx->dictEnd;
|
68
|
+
#ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
|
69
|
+
dctx->dictContentBeginForFuzzing = dctx->prefixStart;
|
70
|
+
dctx->dictContentEndForFuzzing = dctx->previousDstEnd;
|
71
|
+
#endif
|
72
|
+
if (ddict->entropyPresent) {
|
73
|
+
dctx->litEntropy = 1;
|
74
|
+
dctx->fseEntropy = 1;
|
75
|
+
dctx->LLTptr = ddict->entropy.LLTable;
|
76
|
+
dctx->MLTptr = ddict->entropy.MLTable;
|
77
|
+
dctx->OFTptr = ddict->entropy.OFTable;
|
78
|
+
dctx->HUFptr = ddict->entropy.hufTable;
|
79
|
+
dctx->entropy.rep[0] = ddict->entropy.rep[0];
|
80
|
+
dctx->entropy.rep[1] = ddict->entropy.rep[1];
|
81
|
+
dctx->entropy.rep[2] = ddict->entropy.rep[2];
|
82
|
+
} else {
|
83
|
+
dctx->litEntropy = 0;
|
84
|
+
dctx->fseEntropy = 0;
|
85
|
+
}
|
86
|
+
}
|
87
|
+
|
88
|
+
|
89
|
+
static size_t
|
90
|
+
ZSTD_loadEntropy_intoDDict(ZSTD_DDict* ddict,
|
91
|
+
ZSTD_dictContentType_e dictContentType)
|
92
|
+
{
|
93
|
+
ddict->dictID = 0;
|
94
|
+
ddict->entropyPresent = 0;
|
95
|
+
if (dictContentType == ZSTD_dct_rawContent) return 0;
|
96
|
+
|
97
|
+
if (ddict->dictSize < 8) {
|
98
|
+
if (dictContentType == ZSTD_dct_fullDict)
|
99
|
+
return ERROR(dictionary_corrupted); /* only accept specified dictionaries */
|
100
|
+
return 0; /* pure content mode */
|
101
|
+
}
|
102
|
+
{ U32 const magic = MEM_readLE32(ddict->dictContent);
|
103
|
+
if (magic != ZSTD_MAGIC_DICTIONARY) {
|
104
|
+
if (dictContentType == ZSTD_dct_fullDict)
|
105
|
+
return ERROR(dictionary_corrupted); /* only accept specified dictionaries */
|
106
|
+
return 0; /* pure content mode */
|
107
|
+
}
|
108
|
+
}
|
109
|
+
ddict->dictID = MEM_readLE32((const char*)ddict->dictContent + ZSTD_FRAMEIDSIZE);
|
110
|
+
|
111
|
+
/* load entropy tables */
|
112
|
+
RETURN_ERROR_IF(ZSTD_isError(ZSTD_loadDEntropy(
|
113
|
+
&ddict->entropy, ddict->dictContent, ddict->dictSize)),
|
114
|
+
dictionary_corrupted, "");
|
115
|
+
ddict->entropyPresent = 1;
|
116
|
+
return 0;
|
117
|
+
}
|
118
|
+
|
119
|
+
|
120
|
+
static size_t ZSTD_initDDict_internal(ZSTD_DDict* ddict,
|
121
|
+
const void* dict, size_t dictSize,
|
122
|
+
ZSTD_dictLoadMethod_e dictLoadMethod,
|
123
|
+
ZSTD_dictContentType_e dictContentType)
|
124
|
+
{
|
125
|
+
if ((dictLoadMethod == ZSTD_dlm_byRef) || (!dict) || (!dictSize)) {
|
126
|
+
ddict->dictBuffer = NULL;
|
127
|
+
ddict->dictContent = dict;
|
128
|
+
if (!dict) dictSize = 0;
|
129
|
+
} else {
|
130
|
+
void* const internalBuffer = ZSTD_customMalloc(dictSize, ddict->cMem);
|
131
|
+
ddict->dictBuffer = internalBuffer;
|
132
|
+
ddict->dictContent = internalBuffer;
|
133
|
+
if (!internalBuffer) return ERROR(memory_allocation);
|
134
|
+
ZSTD_memcpy(internalBuffer, dict, dictSize);
|
135
|
+
}
|
136
|
+
ddict->dictSize = dictSize;
|
137
|
+
ddict->entropy.hufTable[0] = (HUF_DTable)((ZSTD_HUFFDTABLE_CAPACITY_LOG)*0x1000001); /* cover both little and big endian */
|
138
|
+
|
139
|
+
/* parse dictionary content */
|
140
|
+
FORWARD_IF_ERROR( ZSTD_loadEntropy_intoDDict(ddict, dictContentType) , "");
|
141
|
+
|
142
|
+
return 0;
|
143
|
+
}
|
144
|
+
|
145
|
+
ZSTD_DDict* ZSTD_createDDict_advanced(const void* dict, size_t dictSize,
|
146
|
+
ZSTD_dictLoadMethod_e dictLoadMethod,
|
147
|
+
ZSTD_dictContentType_e dictContentType,
|
148
|
+
ZSTD_customMem customMem)
|
149
|
+
{
|
150
|
+
if ((!customMem.customAlloc) ^ (!customMem.customFree)) return NULL;
|
151
|
+
|
152
|
+
{ ZSTD_DDict* const ddict = (ZSTD_DDict*) ZSTD_customMalloc(sizeof(ZSTD_DDict), customMem);
|
153
|
+
if (ddict == NULL) return NULL;
|
154
|
+
ddict->cMem = customMem;
|
155
|
+
{ size_t const initResult = ZSTD_initDDict_internal(ddict,
|
156
|
+
dict, dictSize,
|
157
|
+
dictLoadMethod, dictContentType);
|
158
|
+
if (ZSTD_isError(initResult)) {
|
159
|
+
ZSTD_freeDDict(ddict);
|
160
|
+
return NULL;
|
161
|
+
} }
|
162
|
+
return ddict;
|
163
|
+
}
|
164
|
+
}
|
165
|
+
|
166
|
+
/*! ZSTD_createDDict() :
|
167
|
+
* Create a digested dictionary, to start decompression without startup delay.
|
168
|
+
* `dict` content is copied inside DDict.
|
169
|
+
* Consequently, `dict` can be released after `ZSTD_DDict` creation */
|
170
|
+
ZSTD_DDict* ZSTD_createDDict(const void* dict, size_t dictSize)
|
171
|
+
{
|
172
|
+
ZSTD_customMem const allocator = { NULL, NULL, NULL };
|
173
|
+
return ZSTD_createDDict_advanced(dict, dictSize, ZSTD_dlm_byCopy, ZSTD_dct_auto, allocator);
|
174
|
+
}
|
175
|
+
|
176
|
+
/*! ZSTD_createDDict_byReference() :
|
177
|
+
* Create a digested dictionary, to start decompression without startup delay.
|
178
|
+
* Dictionary content is simply referenced, it will be accessed during decompression.
|
179
|
+
* Warning : dictBuffer must outlive DDict (DDict must be freed before dictBuffer) */
|
180
|
+
ZSTD_DDict* ZSTD_createDDict_byReference(const void* dictBuffer, size_t dictSize)
|
181
|
+
{
|
182
|
+
ZSTD_customMem const allocator = { NULL, NULL, NULL };
|
183
|
+
return ZSTD_createDDict_advanced(dictBuffer, dictSize, ZSTD_dlm_byRef, ZSTD_dct_auto, allocator);
|
184
|
+
}
|
185
|
+
|
186
|
+
|
187
|
+
const ZSTD_DDict* ZSTD_initStaticDDict(
|
188
|
+
void* sBuffer, size_t sBufferSize,
|
189
|
+
const void* dict, size_t dictSize,
|
190
|
+
ZSTD_dictLoadMethod_e dictLoadMethod,
|
191
|
+
ZSTD_dictContentType_e dictContentType)
|
192
|
+
{
|
193
|
+
size_t const neededSpace = sizeof(ZSTD_DDict)
|
194
|
+
+ (dictLoadMethod == ZSTD_dlm_byRef ? 0 : dictSize);
|
195
|
+
ZSTD_DDict* const ddict = (ZSTD_DDict*)sBuffer;
|
196
|
+
assert(sBuffer != NULL);
|
197
|
+
assert(dict != NULL);
|
198
|
+
if ((size_t)sBuffer & 7) return NULL; /* 8-aligned */
|
199
|
+
if (sBufferSize < neededSpace) return NULL;
|
200
|
+
if (dictLoadMethod == ZSTD_dlm_byCopy) {
|
201
|
+
ZSTD_memcpy(ddict+1, dict, dictSize); /* local copy */
|
202
|
+
dict = ddict+1;
|
203
|
+
}
|
204
|
+
if (ZSTD_isError( ZSTD_initDDict_internal(ddict,
|
205
|
+
dict, dictSize,
|
206
|
+
ZSTD_dlm_byRef, dictContentType) ))
|
207
|
+
return NULL;
|
208
|
+
return ddict;
|
209
|
+
}
|
210
|
+
|
211
|
+
|
212
|
+
size_t ZSTD_freeDDict(ZSTD_DDict* ddict)
|
213
|
+
{
|
214
|
+
if (ddict==NULL) return 0; /* support free on NULL */
|
215
|
+
{ ZSTD_customMem const cMem = ddict->cMem;
|
216
|
+
ZSTD_customFree(ddict->dictBuffer, cMem);
|
217
|
+
ZSTD_customFree(ddict, cMem);
|
218
|
+
return 0;
|
219
|
+
}
|
220
|
+
}
|
221
|
+
|
222
|
+
/*! ZSTD_estimateDDictSize() :
|
223
|
+
* Estimate amount of memory that will be needed to create a dictionary for decompression.
|
224
|
+
* Note : dictionary created by reference using ZSTD_dlm_byRef are smaller */
|
225
|
+
size_t ZSTD_estimateDDictSize(size_t dictSize, ZSTD_dictLoadMethod_e dictLoadMethod)
|
226
|
+
{
|
227
|
+
return sizeof(ZSTD_DDict) + (dictLoadMethod == ZSTD_dlm_byRef ? 0 : dictSize);
|
228
|
+
}
|
229
|
+
|
230
|
+
size_t ZSTD_sizeof_DDict(const ZSTD_DDict* ddict)
|
231
|
+
{
|
232
|
+
if (ddict==NULL) return 0; /* support sizeof on NULL */
|
233
|
+
return sizeof(*ddict) + (ddict->dictBuffer ? ddict->dictSize : 0) ;
|
234
|
+
}
|
235
|
+
|
236
|
+
/*! ZSTD_getDictID_fromDDict() :
|
237
|
+
* Provides the dictID of the dictionary loaded into `ddict`.
|
238
|
+
* If @return == 0, the dictionary is not conformant to Zstandard specification, or empty.
|
239
|
+
* Non-conformant dictionaries can still be loaded, but as content-only dictionaries. */
|
240
|
+
unsigned ZSTD_getDictID_fromDDict(const ZSTD_DDict* ddict)
|
241
|
+
{
|
242
|
+
if (ddict==NULL) return 0;
|
243
|
+
return ddict->dictID;
|
244
|
+
}
|
@@ -0,0 +1,44 @@
|
|
1
|
+
/*
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
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
|
+
|
11
|
+
|
12
|
+
#ifndef ZSTD_DDICT_H
|
13
|
+
#define ZSTD_DDICT_H
|
14
|
+
|
15
|
+
/*-*******************************************************
|
16
|
+
* Dependencies
|
17
|
+
*********************************************************/
|
18
|
+
#include "../common/zstd_deps.h" /* size_t */
|
19
|
+
#include "../zstd.h" /* ZSTD_DDict, and several public functions */
|
20
|
+
|
21
|
+
|
22
|
+
/*-*******************************************************
|
23
|
+
* Interface
|
24
|
+
*********************************************************/
|
25
|
+
|
26
|
+
/* note: several prototypes are already published in `zstd.h` :
|
27
|
+
* ZSTD_createDDict()
|
28
|
+
* ZSTD_createDDict_byReference()
|
29
|
+
* ZSTD_createDDict_advanced()
|
30
|
+
* ZSTD_freeDDict()
|
31
|
+
* ZSTD_initStaticDDict()
|
32
|
+
* ZSTD_sizeof_DDict()
|
33
|
+
* ZSTD_estimateDDictSize()
|
34
|
+
* ZSTD_getDictID_fromDict()
|
35
|
+
*/
|
36
|
+
|
37
|
+
const void* ZSTD_DDict_dictContent(const ZSTD_DDict* ddict);
|
38
|
+
size_t ZSTD_DDict_dictSize(const ZSTD_DDict* ddict);
|
39
|
+
|
40
|
+
void ZSTD_copyDDictParameters(ZSTD_DCtx* dctx, const ZSTD_DDict* ddict);
|
41
|
+
|
42
|
+
|
43
|
+
|
44
|
+
#endif /* ZSTD_DDICT_H */
|