extzstd 0.0.3.CONCEPT → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (138) hide show
  1. checksums.yaml +5 -5
  2. data/HISTORY.ja.md +39 -0
  3. data/LICENSE +6 -6
  4. data/README.md +26 -45
  5. data/contrib/zstd/CHANGELOG +555 -0
  6. data/contrib/zstd/CODE_OF_CONDUCT.md +5 -0
  7. data/contrib/zstd/CONTRIBUTING.md +392 -0
  8. data/contrib/zstd/COPYING +339 -0
  9. data/contrib/zstd/LICENSE +13 -9
  10. data/contrib/zstd/Makefile +414 -0
  11. data/contrib/zstd/README.md +170 -45
  12. data/contrib/zstd/TESTING.md +44 -0
  13. data/contrib/zstd/appveyor.yml +289 -0
  14. data/contrib/zstd/lib/BUCK +234 -0
  15. data/contrib/zstd/lib/Makefile +354 -0
  16. data/contrib/zstd/lib/README.md +179 -0
  17. data/contrib/zstd/{common → lib/common}/bitstream.h +170 -130
  18. data/contrib/zstd/lib/common/compiler.h +175 -0
  19. data/contrib/zstd/lib/common/cpu.h +215 -0
  20. data/contrib/zstd/lib/common/debug.c +24 -0
  21. data/contrib/zstd/lib/common/debug.h +114 -0
  22. data/contrib/zstd/{common → lib/common}/entropy_common.c +79 -94
  23. data/contrib/zstd/lib/common/error_private.c +55 -0
  24. data/contrib/zstd/lib/common/error_private.h +80 -0
  25. data/contrib/zstd/{common → lib/common}/fse.h +153 -93
  26. data/contrib/zstd/{common → lib/common}/fse_decompress.c +37 -82
  27. data/contrib/zstd/lib/common/huf.h +340 -0
  28. data/contrib/zstd/{common → lib/common}/mem.h +154 -78
  29. data/contrib/zstd/lib/common/pool.c +344 -0
  30. data/contrib/zstd/lib/common/pool.h +84 -0
  31. data/contrib/zstd/lib/common/threading.c +121 -0
  32. data/contrib/zstd/lib/common/threading.h +155 -0
  33. data/contrib/zstd/{common → lib/common}/xxhash.c +85 -75
  34. data/contrib/zstd/{common → lib/common}/xxhash.h +85 -73
  35. data/contrib/zstd/lib/common/zstd_common.c +83 -0
  36. data/contrib/zstd/lib/common/zstd_errors.h +94 -0
  37. data/contrib/zstd/lib/common/zstd_internal.h +447 -0
  38. data/contrib/zstd/{compress → lib/compress}/fse_compress.c +194 -303
  39. data/contrib/zstd/lib/compress/hist.c +183 -0
  40. data/contrib/zstd/lib/compress/hist.h +75 -0
  41. data/contrib/zstd/lib/compress/huf_compress.c +798 -0
  42. data/contrib/zstd/lib/compress/zstd_compress.c +4278 -0
  43. data/contrib/zstd/lib/compress/zstd_compress_internal.h +1125 -0
  44. data/contrib/zstd/lib/compress/zstd_compress_literals.c +158 -0
  45. data/contrib/zstd/lib/compress/zstd_compress_literals.h +29 -0
  46. data/contrib/zstd/lib/compress/zstd_compress_sequences.c +419 -0
  47. data/contrib/zstd/lib/compress/zstd_compress_sequences.h +54 -0
  48. data/contrib/zstd/lib/compress/zstd_compress_superblock.c +845 -0
  49. data/contrib/zstd/lib/compress/zstd_compress_superblock.h +32 -0
  50. data/contrib/zstd/lib/compress/zstd_cwksp.h +525 -0
  51. data/contrib/zstd/lib/compress/zstd_double_fast.c +521 -0
  52. data/contrib/zstd/lib/compress/zstd_double_fast.h +38 -0
  53. data/contrib/zstd/lib/compress/zstd_fast.c +496 -0
  54. data/contrib/zstd/lib/compress/zstd_fast.h +37 -0
  55. data/contrib/zstd/lib/compress/zstd_lazy.c +1138 -0
  56. data/contrib/zstd/lib/compress/zstd_lazy.h +67 -0
  57. data/contrib/zstd/lib/compress/zstd_ldm.c +619 -0
  58. data/contrib/zstd/lib/compress/zstd_ldm.h +110 -0
  59. data/contrib/zstd/lib/compress/zstd_opt.c +1200 -0
  60. data/contrib/zstd/lib/compress/zstd_opt.h +56 -0
  61. data/contrib/zstd/lib/compress/zstdmt_compress.c +2143 -0
  62. data/contrib/zstd/lib/compress/zstdmt_compress.h +192 -0
  63. data/contrib/zstd/lib/decompress/huf_decompress.c +1248 -0
  64. data/contrib/zstd/lib/decompress/zstd_ddict.c +244 -0
  65. data/contrib/zstd/lib/decompress/zstd_ddict.h +44 -0
  66. data/contrib/zstd/lib/decompress/zstd_decompress.c +1885 -0
  67. data/contrib/zstd/lib/decompress/zstd_decompress_block.c +1432 -0
  68. data/contrib/zstd/lib/decompress/zstd_decompress_block.h +59 -0
  69. data/contrib/zstd/lib/decompress/zstd_decompress_internal.h +189 -0
  70. data/contrib/zstd/{common → lib/deprecated}/zbuff.h +86 -69
  71. data/contrib/zstd/lib/deprecated/zbuff_common.c +26 -0
  72. data/contrib/zstd/lib/deprecated/zbuff_compress.c +147 -0
  73. data/contrib/zstd/lib/deprecated/zbuff_decompress.c +75 -0
  74. data/contrib/zstd/lib/dictBuilder/cover.c +1236 -0
  75. data/contrib/zstd/lib/dictBuilder/cover.h +157 -0
  76. data/contrib/zstd/{dictBuilder → lib/dictBuilder}/divsufsort.c +3 -3
  77. data/contrib/zstd/{dictBuilder → lib/dictBuilder}/divsufsort.h +5 -5
  78. data/contrib/zstd/lib/dictBuilder/fastcover.c +757 -0
  79. data/contrib/zstd/{dictBuilder → lib/dictBuilder}/zdict.c +437 -347
  80. data/contrib/zstd/lib/dictBuilder/zdict.h +305 -0
  81. data/contrib/zstd/lib/legacy/zstd_legacy.h +415 -0
  82. data/contrib/zstd/{legacy → lib/legacy}/zstd_v01.c +272 -292
  83. data/contrib/zstd/{legacy → lib/legacy}/zstd_v01.h +26 -32
  84. data/contrib/zstd/{legacy → lib/legacy}/zstd_v02.c +162 -392
  85. data/contrib/zstd/{legacy → lib/legacy}/zstd_v02.h +26 -32
  86. data/contrib/zstd/{legacy → lib/legacy}/zstd_v03.c +162 -391
  87. data/contrib/zstd/{legacy → lib/legacy}/zstd_v03.h +27 -33
  88. data/contrib/zstd/{legacy → lib/legacy}/zstd_v04.c +195 -604
  89. data/contrib/zstd/{legacy → lib/legacy}/zstd_v04.h +26 -32
  90. data/contrib/zstd/{legacy → lib/legacy}/zstd_v05.c +300 -575
  91. data/contrib/zstd/{legacy → lib/legacy}/zstd_v05.h +22 -31
  92. data/contrib/zstd/{legacy → lib/legacy}/zstd_v06.c +165 -592
  93. data/contrib/zstd/{legacy → lib/legacy}/zstd_v06.h +54 -67
  94. data/contrib/zstd/lib/legacy/zstd_v07.c +4541 -0
  95. data/contrib/zstd/lib/legacy/zstd_v07.h +187 -0
  96. data/contrib/zstd/lib/libzstd.pc.in +15 -0
  97. data/contrib/zstd/lib/zstd.h +2090 -0
  98. data/ext/depend +2 -0
  99. data/ext/extconf.rb +18 -5
  100. data/ext/extzstd.c +296 -214
  101. data/ext/extzstd.h +81 -36
  102. data/ext/extzstd_nogvls.h +0 -117
  103. data/ext/extzstd_stream.c +622 -0
  104. data/ext/libzstd_conf.h +8 -0
  105. data/ext/zstd_common.c +11 -0
  106. data/ext/zstd_compress.c +15 -0
  107. data/ext/zstd_decompress.c +6 -0
  108. data/ext/zstd_dictbuilder.c +10 -0
  109. data/ext/zstd_dictbuilder_fastcover.c +3 -0
  110. data/ext/zstd_legacy_v01.c +3 -1
  111. data/ext/zstd_legacy_v02.c +3 -1
  112. data/ext/zstd_legacy_v03.c +3 -1
  113. data/ext/zstd_legacy_v04.c +3 -1
  114. data/ext/zstd_legacy_v05.c +3 -1
  115. data/ext/zstd_legacy_v06.c +3 -1
  116. data/ext/zstd_legacy_v07.c +3 -0
  117. data/gemstub.rb +27 -21
  118. data/lib/extzstd.rb +82 -161
  119. data/lib/extzstd/version.rb +1 -1
  120. data/test/test_basic.rb +19 -6
  121. metadata +127 -59
  122. data/contrib/zstd/common/error_private.h +0 -125
  123. data/contrib/zstd/common/error_public.h +0 -77
  124. data/contrib/zstd/common/huf.h +0 -228
  125. data/contrib/zstd/common/zstd.h +0 -475
  126. data/contrib/zstd/common/zstd_common.c +0 -91
  127. data/contrib/zstd/common/zstd_internal.h +0 -238
  128. data/contrib/zstd/compress/huf_compress.c +0 -577
  129. data/contrib/zstd/compress/zbuff_compress.c +0 -327
  130. data/contrib/zstd/compress/zstd_compress.c +0 -3074
  131. data/contrib/zstd/compress/zstd_opt.h +0 -1046
  132. data/contrib/zstd/decompress/huf_decompress.c +0 -894
  133. data/contrib/zstd/decompress/zbuff_decompress.c +0 -294
  134. data/contrib/zstd/decompress/zstd_decompress.c +0 -1362
  135. data/contrib/zstd/dictBuilder/zdict.h +0 -113
  136. data/contrib/zstd/legacy/zstd_legacy.h +0 -140
  137. data/ext/extzstd_buffered.c +0 -265
  138. data/ext/zstd_amalgam.c +0 -18
@@ -0,0 +1,59 @@
1
+ /*
2
+ * Copyright (c) 2016-2020, 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
+
11
+
12
+ #ifndef ZSTD_DEC_BLOCK_H
13
+ #define ZSTD_DEC_BLOCK_H
14
+
15
+ /*-*******************************************************
16
+ * Dependencies
17
+ *********************************************************/
18
+ #include <stddef.h> /* size_t */
19
+ #include "../zstd.h" /* DCtx, and some public functions */
20
+ #include "../common/zstd_internal.h" /* blockProperties_t, and some public functions */
21
+ #include "zstd_decompress_internal.h" /* ZSTD_seqSymbol */
22
+
23
+
24
+ /* === Prototypes === */
25
+
26
+ /* note: prototypes already published within `zstd.h` :
27
+ * ZSTD_decompressBlock()
28
+ */
29
+
30
+ /* note: prototypes already published within `zstd_internal.h` :
31
+ * ZSTD_getcBlockSize()
32
+ * ZSTD_decodeSeqHeaders()
33
+ */
34
+
35
+
36
+ /* ZSTD_decompressBlock_internal() :
37
+ * decompress block, starting at `src`,
38
+ * into destination buffer `dst`.
39
+ * @return : decompressed block size,
40
+ * or an error code (which can be tested using ZSTD_isError())
41
+ */
42
+ size_t ZSTD_decompressBlock_internal(ZSTD_DCtx* dctx,
43
+ void* dst, size_t dstCapacity,
44
+ const void* src, size_t srcSize, const int frame);
45
+
46
+ /* ZSTD_buildFSETable() :
47
+ * generate FSE decoding table for one symbol (ll, ml or off)
48
+ * this function must be called with valid parameters only
49
+ * (dt is large enough, normalizedCounter distribution total is a power of 2, max is within range, etc.)
50
+ * in which case it cannot fail.
51
+ * Internal use only.
52
+ */
53
+ void ZSTD_buildFSETable(ZSTD_seqSymbol* dt,
54
+ const short* normalizedCounter, unsigned maxSymbolValue,
55
+ const U32* baseValue, const U32* nbAdditionalBits,
56
+ unsigned tableLog);
57
+
58
+
59
+ #endif /* ZSTD_DEC_BLOCK_H */
@@ -0,0 +1,189 @@
1
+ /*
2
+ * Copyright (c) 2016-2020, 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
+
11
+
12
+ /* zstd_decompress_internal:
13
+ * objects and definitions shared within lib/decompress modules */
14
+
15
+ #ifndef ZSTD_DECOMPRESS_INTERNAL_H
16
+ #define ZSTD_DECOMPRESS_INTERNAL_H
17
+
18
+
19
+ /*-*******************************************************
20
+ * Dependencies
21
+ *********************************************************/
22
+ #include "../common/mem.h" /* BYTE, U16, U32 */
23
+ #include "../common/zstd_internal.h" /* ZSTD_seqSymbol */
24
+
25
+
26
+
27
+ /*-*******************************************************
28
+ * Constants
29
+ *********************************************************/
30
+ static const U32 LL_base[MaxLL+1] = {
31
+ 0, 1, 2, 3, 4, 5, 6, 7,
32
+ 8, 9, 10, 11, 12, 13, 14, 15,
33
+ 16, 18, 20, 22, 24, 28, 32, 40,
34
+ 48, 64, 0x80, 0x100, 0x200, 0x400, 0x800, 0x1000,
35
+ 0x2000, 0x4000, 0x8000, 0x10000 };
36
+
37
+ static const U32 OF_base[MaxOff+1] = {
38
+ 0, 1, 1, 5, 0xD, 0x1D, 0x3D, 0x7D,
39
+ 0xFD, 0x1FD, 0x3FD, 0x7FD, 0xFFD, 0x1FFD, 0x3FFD, 0x7FFD,
40
+ 0xFFFD, 0x1FFFD, 0x3FFFD, 0x7FFFD, 0xFFFFD, 0x1FFFFD, 0x3FFFFD, 0x7FFFFD,
41
+ 0xFFFFFD, 0x1FFFFFD, 0x3FFFFFD, 0x7FFFFFD, 0xFFFFFFD, 0x1FFFFFFD, 0x3FFFFFFD, 0x7FFFFFFD };
42
+
43
+ static const U32 OF_bits[MaxOff+1] = {
44
+ 0, 1, 2, 3, 4, 5, 6, 7,
45
+ 8, 9, 10, 11, 12, 13, 14, 15,
46
+ 16, 17, 18, 19, 20, 21, 22, 23,
47
+ 24, 25, 26, 27, 28, 29, 30, 31 };
48
+
49
+ static const U32 ML_base[MaxML+1] = {
50
+ 3, 4, 5, 6, 7, 8, 9, 10,
51
+ 11, 12, 13, 14, 15, 16, 17, 18,
52
+ 19, 20, 21, 22, 23, 24, 25, 26,
53
+ 27, 28, 29, 30, 31, 32, 33, 34,
54
+ 35, 37, 39, 41, 43, 47, 51, 59,
55
+ 67, 83, 99, 0x83, 0x103, 0x203, 0x403, 0x803,
56
+ 0x1003, 0x2003, 0x4003, 0x8003, 0x10003 };
57
+
58
+
59
+ /*-*******************************************************
60
+ * Decompression types
61
+ *********************************************************/
62
+ typedef struct {
63
+ U32 fastMode;
64
+ U32 tableLog;
65
+ } ZSTD_seqSymbol_header;
66
+
67
+ typedef struct {
68
+ U16 nextState;
69
+ BYTE nbAdditionalBits;
70
+ BYTE nbBits;
71
+ U32 baseValue;
72
+ } ZSTD_seqSymbol;
73
+
74
+ #define SEQSYMBOL_TABLE_SIZE(log) (1 + (1 << (log)))
75
+
76
+ typedef struct {
77
+ ZSTD_seqSymbol LLTable[SEQSYMBOL_TABLE_SIZE(LLFSELog)]; /* Note : Space reserved for FSE Tables */
78
+ ZSTD_seqSymbol OFTable[SEQSYMBOL_TABLE_SIZE(OffFSELog)]; /* is also used as temporary workspace while building hufTable during DDict creation */
79
+ ZSTD_seqSymbol MLTable[SEQSYMBOL_TABLE_SIZE(MLFSELog)]; /* and therefore must be at least HUF_DECOMPRESS_WORKSPACE_SIZE large */
80
+ HUF_DTable hufTable[HUF_DTABLE_SIZE(HufLog)]; /* can accommodate HUF_decompress4X */
81
+ U32 rep[ZSTD_REP_NUM];
82
+ } ZSTD_entropyDTables_t;
83
+
84
+ typedef enum { ZSTDds_getFrameHeaderSize, ZSTDds_decodeFrameHeader,
85
+ ZSTDds_decodeBlockHeader, ZSTDds_decompressBlock,
86
+ ZSTDds_decompressLastBlock, ZSTDds_checkChecksum,
87
+ ZSTDds_decodeSkippableHeader, ZSTDds_skipFrame } ZSTD_dStage;
88
+
89
+ typedef enum { zdss_init=0, zdss_loadHeader,
90
+ zdss_read, zdss_load, zdss_flush } ZSTD_dStreamStage;
91
+
92
+ typedef enum {
93
+ ZSTD_use_indefinitely = -1, /* Use the dictionary indefinitely */
94
+ ZSTD_dont_use = 0, /* Do not use the dictionary (if one exists free it) */
95
+ ZSTD_use_once = 1 /* Use the dictionary once and set to ZSTD_dont_use */
96
+ } ZSTD_dictUses_e;
97
+
98
+ typedef enum {
99
+ ZSTD_obm_buffered = 0, /* Buffer the output */
100
+ ZSTD_obm_stable = 1 /* ZSTD_outBuffer is stable */
101
+ } ZSTD_outBufferMode_e;
102
+
103
+ struct ZSTD_DCtx_s
104
+ {
105
+ const ZSTD_seqSymbol* LLTptr;
106
+ const ZSTD_seqSymbol* MLTptr;
107
+ const ZSTD_seqSymbol* OFTptr;
108
+ const HUF_DTable* HUFptr;
109
+ ZSTD_entropyDTables_t entropy;
110
+ U32 workspace[HUF_DECOMPRESS_WORKSPACE_SIZE_U32]; /* space needed when building huffman tables */
111
+ const void* previousDstEnd; /* detect continuity */
112
+ const void* prefixStart; /* start of current segment */
113
+ const void* virtualStart; /* virtual start of previous segment if it was just before current one */
114
+ const void* dictEnd; /* end of previous segment */
115
+ size_t expected;
116
+ ZSTD_frameHeader fParams;
117
+ U64 decodedSize;
118
+ blockType_e bType; /* used in ZSTD_decompressContinue(), store blockType between block header decoding and block decompression stages */
119
+ ZSTD_dStage stage;
120
+ U32 litEntropy;
121
+ U32 fseEntropy;
122
+ XXH64_state_t xxhState;
123
+ size_t headerSize;
124
+ ZSTD_format_e format;
125
+ const BYTE* litPtr;
126
+ ZSTD_customMem customMem;
127
+ size_t litSize;
128
+ size_t rleSize;
129
+ size_t staticSize;
130
+ int bmi2; /* == 1 if the CPU supports BMI2 and 0 otherwise. CPU support is determined dynamically once per context lifetime. */
131
+
132
+ /* dictionary */
133
+ ZSTD_DDict* ddictLocal;
134
+ const ZSTD_DDict* ddict; /* set by ZSTD_initDStream_usingDDict(), or ZSTD_DCtx_refDDict() */
135
+ U32 dictID;
136
+ int ddictIsCold; /* if == 1 : dictionary is "new" for working context, and presumed "cold" (not in cpu cache) */
137
+ ZSTD_dictUses_e dictUses;
138
+
139
+ /* streaming */
140
+ ZSTD_dStreamStage streamStage;
141
+ char* inBuff;
142
+ size_t inBuffSize;
143
+ size_t inPos;
144
+ size_t maxWindowSize;
145
+ char* outBuff;
146
+ size_t outBuffSize;
147
+ size_t outStart;
148
+ size_t outEnd;
149
+ size_t lhSize;
150
+ void* legacyContext;
151
+ U32 previousLegacyVersion;
152
+ U32 legacyVersion;
153
+ U32 hostageByte;
154
+ int noForwardProgress;
155
+ ZSTD_outBufferMode_e outBufferMode;
156
+ ZSTD_outBuffer expectedOutBuffer;
157
+
158
+ /* workspace */
159
+ BYTE litBuffer[ZSTD_BLOCKSIZE_MAX + WILDCOPY_OVERLENGTH];
160
+ BYTE headerBuffer[ZSTD_FRAMEHEADERSIZE_MAX];
161
+
162
+ size_t oversizedDuration;
163
+
164
+ #ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
165
+ void const* dictContentBeginForFuzzing;
166
+ void const* dictContentEndForFuzzing;
167
+ #endif
168
+ }; /* typedef'd to ZSTD_DCtx within "zstd.h" */
169
+
170
+
171
+ /*-*******************************************************
172
+ * Shared internal functions
173
+ *********************************************************/
174
+
175
+ /*! ZSTD_loadDEntropy() :
176
+ * dict : must point at beginning of a valid zstd dictionary.
177
+ * @return : size of dictionary header (size of magic number + dict ID + entropy tables) */
178
+ size_t ZSTD_loadDEntropy(ZSTD_entropyDTables_t* entropy,
179
+ const void* const dict, size_t const dictSize);
180
+
181
+ /*! ZSTD_checkContinuity() :
182
+ * check if next `dst` follows previous position, where decompression ended.
183
+ * If yes, do nothing (continue on current segment).
184
+ * If not, classify previous segment as "external dictionary", and start a new segment.
185
+ * This function cannot fail. */
186
+ void ZSTD_checkContinuity(ZSTD_DCtx* dctx, const void* dst);
187
+
188
+
189
+ #endif /* ZSTD_DECOMPRESS_INTERNAL_H */
@@ -1,71 +1,83 @@
1
1
  /*
2
- Buffered version of Zstd compression library
3
- Copyright (C) 2015-2016, Yann Collet.
4
-
5
- BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
6
-
7
- Redistribution and use in source and binary forms, with or without
8
- modification, are permitted provided that the following conditions are
9
- met:
10
- * Redistributions of source code must retain the above copyright
11
- notice, this list of conditions and the following disclaimer.
12
- * Redistributions in binary form must reproduce the above
13
- copyright notice, this list of conditions and the following disclaimer
14
- in the documentation and/or other materials provided with the
15
- distribution.
16
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17
- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18
- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19
- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20
- OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21
- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22
- LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23
- DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24
- THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25
- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26
- OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
-
28
- You can contact the author at :
29
- - zstd homepage : http://www.zstd.net/
30
- */
31
- #ifndef ZSTD_BUFFERED_H_23987
32
- #define ZSTD_BUFFERED_H_23987
2
+ * Copyright (c) 2016-2020, 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
+
11
+ /* ***************************************************************
12
+ * NOTES/WARNINGS
13
+ ******************************************************************/
14
+ /* The streaming API defined here is deprecated.
15
+ * Consider migrating towards ZSTD_compressStream() API in `zstd.h`
16
+ * See 'lib/README.md'.
17
+ *****************************************************************/
18
+
33
19
 
34
20
  #if defined (__cplusplus)
35
21
  extern "C" {
36
22
  #endif
37
23
 
24
+ #ifndef ZSTD_BUFFERED_H_23987
25
+ #define ZSTD_BUFFERED_H_23987
26
+
38
27
  /* *************************************
39
28
  * Dependencies
40
29
  ***************************************/
41
30
  #include <stddef.h> /* size_t */
31
+ #include "../zstd.h" /* ZSTD_CStream, ZSTD_DStream, ZSTDLIB_API */
42
32
 
43
33
 
44
34
  /* ***************************************************************
45
35
  * Compiler specifics
46
36
  *****************************************************************/
47
- /* ZSTD_DLL_EXPORT :
48
- * Enable exporting of functions when building a Windows DLL */
49
- #if defined(_WIN32) && defined(ZSTD_DLL_EXPORT) && (ZSTD_DLL_EXPORT==1)
50
- # define ZSTDLIB_API __declspec(dllexport)
37
+ /* Deprecation warnings */
38
+ /* Should these warnings be a problem,
39
+ * it is generally possible to disable them,
40
+ * typically with -Wno-deprecated-declarations for gcc
41
+ * or _CRT_SECURE_NO_WARNINGS in Visual.
42
+ * Otherwise, it's also possible to define ZBUFF_DISABLE_DEPRECATE_WARNINGS
43
+ */
44
+ #ifdef ZBUFF_DISABLE_DEPRECATE_WARNINGS
45
+ # define ZBUFF_DEPRECATED(message) ZSTDLIB_API /* disable deprecation warnings */
51
46
  #else
52
- # define ZSTDLIB_API
53
- #endif
47
+ # if defined (__cplusplus) && (__cplusplus >= 201402) /* C++14 or greater */
48
+ # define ZBUFF_DEPRECATED(message) [[deprecated(message)]] ZSTDLIB_API
49
+ # elif (defined(GNUC) && (GNUC > 4 || (GNUC == 4 && GNUC_MINOR >= 5))) || defined(__clang__)
50
+ # define ZBUFF_DEPRECATED(message) ZSTDLIB_API __attribute__((deprecated(message)))
51
+ # elif defined(__GNUC__) && (__GNUC__ >= 3)
52
+ # define ZBUFF_DEPRECATED(message) ZSTDLIB_API __attribute__((deprecated))
53
+ # elif defined(_MSC_VER)
54
+ # define ZBUFF_DEPRECATED(message) ZSTDLIB_API __declspec(deprecated(message))
55
+ # else
56
+ # pragma message("WARNING: You need to implement ZBUFF_DEPRECATED for this compiler")
57
+ # define ZBUFF_DEPRECATED(message) ZSTDLIB_API
58
+ # endif
59
+ #endif /* ZBUFF_DISABLE_DEPRECATE_WARNINGS */
54
60
 
55
61
 
56
62
  /* *************************************
57
63
  * Streaming functions
58
64
  ***************************************/
59
- typedef struct ZBUFF_CCtx_s ZBUFF_CCtx;
60
- ZSTDLIB_API ZBUFF_CCtx* ZBUFF_createCCtx(void);
61
- ZSTDLIB_API size_t ZBUFF_freeCCtx(ZBUFF_CCtx* cctx);
65
+ /* This is the easier "buffered" streaming API,
66
+ * using an internal buffer to lift all restrictions on user-provided buffers
67
+ * which can be any size, any place, for both input and output.
68
+ * ZBUFF and ZSTD are 100% interoperable,
69
+ * frames created by one can be decoded by the other one */
70
+
71
+ typedef ZSTD_CStream ZBUFF_CCtx;
72
+ ZBUFF_DEPRECATED("use ZSTD_createCStream") ZBUFF_CCtx* ZBUFF_createCCtx(void);
73
+ ZBUFF_DEPRECATED("use ZSTD_freeCStream") size_t ZBUFF_freeCCtx(ZBUFF_CCtx* cctx);
62
74
 
63
- ZSTDLIB_API size_t ZBUFF_compressInit(ZBUFF_CCtx* cctx, int compressionLevel);
64
- ZSTDLIB_API size_t ZBUFF_compressInitDictionary(ZBUFF_CCtx* cctx, const void* dict, size_t dictSize, int compressionLevel);
75
+ ZBUFF_DEPRECATED("use ZSTD_initCStream") size_t ZBUFF_compressInit(ZBUFF_CCtx* cctx, int compressionLevel);
76
+ ZBUFF_DEPRECATED("use ZSTD_initCStream_usingDict") size_t ZBUFF_compressInitDictionary(ZBUFF_CCtx* cctx, const void* dict, size_t dictSize, int compressionLevel);
65
77
 
66
- ZSTDLIB_API size_t ZBUFF_compressContinue(ZBUFF_CCtx* cctx, void* dst, size_t* dstCapacityPtr, const void* src, size_t* srcSizePtr);
67
- ZSTDLIB_API size_t ZBUFF_compressFlush(ZBUFF_CCtx* cctx, void* dst, size_t* dstCapacityPtr);
68
- ZSTDLIB_API size_t ZBUFF_compressEnd(ZBUFF_CCtx* cctx, void* dst, size_t* dstCapacityPtr);
78
+ ZBUFF_DEPRECATED("use ZSTD_compressStream") size_t ZBUFF_compressContinue(ZBUFF_CCtx* cctx, void* dst, size_t* dstCapacityPtr, const void* src, size_t* srcSizePtr);
79
+ ZBUFF_DEPRECATED("use ZSTD_flushStream") size_t ZBUFF_compressFlush(ZBUFF_CCtx* cctx, void* dst, size_t* dstCapacityPtr);
80
+ ZBUFF_DEPRECATED("use ZSTD_endStream") size_t ZBUFF_compressEnd(ZBUFF_CCtx* cctx, void* dst, size_t* dstCapacityPtr);
69
81
 
70
82
  /*-*************************************************
71
83
  * Streaming compression - howto
@@ -108,14 +120,14 @@ ZSTDLIB_API size_t ZBUFF_compressEnd(ZBUFF_CCtx* cctx, void* dst, size_t* dstCap
108
120
  * **************************************************/
109
121
 
110
122
 
111
- typedef struct ZBUFF_DCtx_s ZBUFF_DCtx;
112
- ZSTDLIB_API ZBUFF_DCtx* ZBUFF_createDCtx(void);
113
- ZSTDLIB_API size_t ZBUFF_freeDCtx(ZBUFF_DCtx* dctx);
123
+ typedef ZSTD_DStream ZBUFF_DCtx;
124
+ ZBUFF_DEPRECATED("use ZSTD_createDStream") ZBUFF_DCtx* ZBUFF_createDCtx(void);
125
+ ZBUFF_DEPRECATED("use ZSTD_freeDStream") size_t ZBUFF_freeDCtx(ZBUFF_DCtx* dctx);
114
126
 
115
- ZSTDLIB_API size_t ZBUFF_decompressInit(ZBUFF_DCtx* dctx);
116
- ZSTDLIB_API size_t ZBUFF_decompressInitDictionary(ZBUFF_DCtx* dctx, const void* dict, size_t dictSize);
127
+ ZBUFF_DEPRECATED("use ZSTD_initDStream") size_t ZBUFF_decompressInit(ZBUFF_DCtx* dctx);
128
+ ZBUFF_DEPRECATED("use ZSTD_initDStream_usingDict") size_t ZBUFF_decompressInitDictionary(ZBUFF_DCtx* dctx, const void* dict, size_t dictSize);
117
129
 
118
- ZSTDLIB_API size_t ZBUFF_decompressContinue(ZBUFF_DCtx* dctx,
130
+ ZBUFF_DEPRECATED("use ZSTD_decompressStream") size_t ZBUFF_decompressContinue(ZBUFF_DCtx* dctx,
119
131
  void* dst, size_t* dstCapacityPtr,
120
132
  const void* src, size_t* srcSizePtr);
121
133
 
@@ -133,8 +145,9 @@ ZSTDLIB_API size_t ZBUFF_decompressContinue(ZBUFF_DCtx* dctx,
133
145
  * The function will report how many bytes were read or written by modifying *srcSizePtr and *dstCapacityPtr.
134
146
  * Note that it may not consume the entire input, in which case it's up to the caller to present remaining input again.
135
147
  * The content of `dst` will be overwritten (up to *dstCapacityPtr) at each function call, so save its content if it matters, or change `dst`.
136
- * @return : a hint to preferred nb of bytes to use as input for next function call (it's only a hint, to help latency),
137
- * or 0 when a frame is completely decoded,
148
+ * @return : 0 when a frame is completely decoded and fully flushed,
149
+ * 1 when there is still some data left within internal buffer to flush,
150
+ * >1 when more data is expected, with value being a suggested next input size (it's just a hint, which helps latency),
138
151
  * or an error code, which can be tested using ZBUFF_isError().
139
152
  *
140
153
  * Hint : recommended buffer sizes (not compulsory) : ZBUFF_recommendedDInSize() and ZBUFF_recommendedDOutSize()
@@ -147,18 +160,22 @@ ZSTDLIB_API size_t ZBUFF_decompressContinue(ZBUFF_DCtx* dctx,
147
160
  /* *************************************
148
161
  * Tool functions
149
162
  ***************************************/
150
- ZSTDLIB_API unsigned ZBUFF_isError(size_t errorCode);
151
- ZSTDLIB_API const char* ZBUFF_getErrorName(size_t errorCode);
163
+ ZBUFF_DEPRECATED("use ZSTD_isError") unsigned ZBUFF_isError(size_t errorCode);
164
+ ZBUFF_DEPRECATED("use ZSTD_getErrorName") const char* ZBUFF_getErrorName(size_t errorCode);
152
165
 
153
166
  /** Functions below provide recommended buffer sizes for Compression or Decompression operations.
154
167
  * These sizes are just hints, they tend to offer better latency */
155
- ZSTDLIB_API size_t ZBUFF_recommendedCInSize(void);
156
- ZSTDLIB_API size_t ZBUFF_recommendedCOutSize(void);
157
- ZSTDLIB_API size_t ZBUFF_recommendedDInSize(void);
158
- ZSTDLIB_API size_t ZBUFF_recommendedDOutSize(void);
168
+ ZBUFF_DEPRECATED("use ZSTD_CStreamInSize") size_t ZBUFF_recommendedCInSize(void);
169
+ ZBUFF_DEPRECATED("use ZSTD_CStreamOutSize") size_t ZBUFF_recommendedCOutSize(void);
170
+ ZBUFF_DEPRECATED("use ZSTD_DStreamInSize") size_t ZBUFF_recommendedDInSize(void);
171
+ ZBUFF_DEPRECATED("use ZSTD_DStreamOutSize") size_t ZBUFF_recommendedDOutSize(void);
172
+
173
+ #endif /* ZSTD_BUFFERED_H_23987 */
159
174
 
160
175
 
161
176
  #ifdef ZBUFF_STATIC_LINKING_ONLY
177
+ #ifndef ZBUFF_STATIC_H_30298098432
178
+ #define ZBUFF_STATIC_H_30298098432
162
179
 
163
180
  /* ====================================================================================
164
181
  * The definitions in this section are considered experimental.
@@ -168,30 +185,30 @@ ZSTDLIB_API size_t ZBUFF_recommendedDOutSize(void);
168
185
  * ==================================================================================== */
169
186
 
170
187
  /*--- Dependency ---*/
171
- #define ZSTD_STATIC_LINKING_ONLY /* ZSTD_parameters */
172
- #include "zstd.h"
188
+ #define ZSTD_STATIC_LINKING_ONLY /* ZSTD_parameters, ZSTD_customMem */
189
+ #include "../zstd.h"
173
190
 
174
191
 
175
- /*--- External memory ---*/
192
+ /*--- Custom memory allocator ---*/
176
193
  /*! ZBUFF_createCCtx_advanced() :
177
194
  * Create a ZBUFF compression context using external alloc and free functions */
178
- ZSTDLIB_API ZBUFF_CCtx* ZBUFF_createCCtx_advanced(ZSTD_customMem customMem);
195
+ ZBUFF_DEPRECATED("use ZSTD_createCStream_advanced") ZBUFF_CCtx* ZBUFF_createCCtx_advanced(ZSTD_customMem customMem);
179
196
 
180
197
  /*! ZBUFF_createDCtx_advanced() :
181
198
  * Create a ZBUFF decompression context using external alloc and free functions */
182
- ZSTDLIB_API ZBUFF_DCtx* ZBUFF_createDCtx_advanced(ZSTD_customMem customMem);
199
+ ZBUFF_DEPRECATED("use ZSTD_createDStream_advanced") ZBUFF_DCtx* ZBUFF_createDCtx_advanced(ZSTD_customMem customMem);
183
200
 
184
201
 
185
- /*--- Advanced Streaming function ---*/
186
- ZSTDLIB_API size_t ZBUFF_compressInit_advanced(ZBUFF_CCtx* zbc,
202
+ /*--- Advanced Streaming Initialization ---*/
203
+ ZBUFF_DEPRECATED("use ZSTD_initDStream_usingDict") size_t ZBUFF_compressInit_advanced(ZBUFF_CCtx* zbc,
187
204
  const void* dict, size_t dictSize,
188
205
  ZSTD_parameters params, unsigned long long pledgedSrcSize);
189
206
 
190
- #endif /* ZBUFF_STATIC_LINKING_ONLY */
207
+
208
+ #endif /* ZBUFF_STATIC_H_30298098432 */
209
+ #endif /* ZBUFF_STATIC_LINKING_ONLY */
191
210
 
192
211
 
193
212
  #if defined (__cplusplus)
194
213
  }
195
214
  #endif
196
-
197
- #endif /* ZSTD_BUFFERED_H_23987 */