extzstd 0.0.3.CONCEPT → 0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/HISTORY.ja +5 -0
- data/LICENSE +6 -6
- data/README.md +35 -22
- data/contrib/zstd/LICENSE +13 -9
- data/contrib/zstd/README.md +37 -44
- data/contrib/zstd/common/entropy_common.c +33 -39
- data/contrib/zstd/common/error_private.c +43 -0
- data/contrib/zstd/common/error_private.h +11 -60
- data/contrib/zstd/common/fse.h +11 -5
- data/contrib/zstd/common/fse_decompress.c +14 -16
- data/contrib/zstd/common/huf.h +1 -1
- data/contrib/zstd/common/mem.h +36 -43
- data/contrib/zstd/common/xxhash.c +31 -18
- data/contrib/zstd/common/xxhash.h +71 -35
- data/contrib/zstd/common/zbuff.h +29 -35
- data/contrib/zstd/common/zstd_common.c +24 -32
- data/contrib/zstd/common/zstd_errors.h +60 -0
- data/contrib/zstd/common/zstd_internal.h +109 -80
- data/contrib/zstd/compress/fse_compress.c +9 -6
- data/contrib/zstd/compress/huf_compress.c +30 -74
- data/contrib/zstd/compress/zbuff_compress.c +43 -51
- data/contrib/zstd/compress/zstd_compress.c +953 -763
- data/contrib/zstd/compress/zstd_opt.h +115 -261
- data/contrib/zstd/decompress/huf_decompress.c +29 -40
- data/contrib/zstd/decompress/zbuff_decompress.c +36 -78
- data/contrib/zstd/decompress/zstd_decompress.c +976 -496
- data/contrib/zstd/dictBuilder/divsufsort.h +5 -5
- data/contrib/zstd/dictBuilder/zdict.c +194 -229
- data/contrib/zstd/dictBuilder/zdict.h +66 -68
- data/contrib/zstd/legacy/zstd_legacy.h +168 -49
- data/contrib/zstd/legacy/zstd_v01.c +95 -178
- data/contrib/zstd/legacy/zstd_v01.h +12 -32
- data/contrib/zstd/legacy/zstd_v02.c +48 -274
- data/contrib/zstd/legacy/zstd_v02.h +12 -32
- data/contrib/zstd/legacy/zstd_v03.c +48 -274
- data/contrib/zstd/legacy/zstd_v03.h +12 -32
- data/contrib/zstd/legacy/zstd_v04.c +63 -320
- data/contrib/zstd/legacy/zstd_v04.h +13 -33
- data/contrib/zstd/legacy/zstd_v05.c +80 -345
- data/contrib/zstd/legacy/zstd_v05.h +9 -31
- data/contrib/zstd/legacy/zstd_v06.c +48 -458
- data/contrib/zstd/legacy/zstd_v06.h +41 -67
- data/contrib/zstd/legacy/zstd_v07.c +4544 -0
- data/contrib/zstd/legacy/zstd_v07.h +173 -0
- data/contrib/zstd/zstd.h +640 -0
- data/ext/extconf.rb +7 -3
- data/ext/extzstd.c +263 -106
- data/ext/extzstd.h +8 -6
- data/ext/extzstd_nogvls.h +0 -117
- data/ext/extzstd_stream.c +347 -0
- data/ext/zstd_common.c +8 -0
- data/ext/zstd_compress.c +6 -0
- data/ext/zstd_decompress.c +5 -0
- data/ext/zstd_dictbuilder.c +5 -0
- data/ext/zstd_legacy_v07.c +1 -0
- data/gemstub.rb +18 -16
- data/lib/extzstd/version.rb +1 -1
- data/lib/extzstd.rb +77 -43
- data/test/test_basic.rb +11 -6
- metadata +23 -10
- data/contrib/zstd/common/error_public.h +0 -77
- data/contrib/zstd/common/zstd.h +0 -475
- data/ext/extzstd_buffered.c +0 -265
- data/ext/zstd_amalgam.c +0 -18
@@ -35,24 +35,8 @@
|
|
35
35
|
/* **************************************************************
|
36
36
|
* Compiler specifics
|
37
37
|
****************************************************************/
|
38
|
-
#if defined (__cplusplus) || (defined (__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) /* C99 */)
|
39
|
-
/* inline is defined */
|
40
|
-
#elif defined(_MSC_VER)
|
41
|
-
# define inline __inline
|
42
|
-
#else
|
43
|
-
# define inline /* disable inline */
|
44
|
-
#endif
|
45
|
-
|
46
|
-
|
47
38
|
#ifdef _MSC_VER /* Visual Studio */
|
48
|
-
# define FORCE_INLINE static __forceinline
|
49
39
|
# pragma warning(disable : 4127) /* disable: C4127: conditional expression is constant */
|
50
|
-
#else
|
51
|
-
# ifdef __GNUC__
|
52
|
-
# define FORCE_INLINE static inline __attribute__((always_inline))
|
53
|
-
# else
|
54
|
-
# define FORCE_INLINE static inline
|
55
|
-
# endif
|
56
40
|
#endif
|
57
41
|
|
58
42
|
|
@@ -89,7 +73,7 @@ unsigned HUF_optimalTableLog(unsigned maxTableLog, size_t srcSize, unsigned maxS
|
|
89
73
|
struct HUF_CElt_s {
|
90
74
|
U16 val;
|
91
75
|
BYTE nbBits;
|
92
|
-
}; /* typedef'd to HUF_CElt within
|
76
|
+
}; /* typedef'd to HUF_CElt within "huf.h" */
|
93
77
|
|
94
78
|
typedef struct nodeElt_s {
|
95
79
|
U32 count;
|
@@ -105,66 +89,38 @@ size_t HUF_writeCTable (void* dst, size_t maxDstSize,
|
|
105
89
|
const HUF_CElt* CTable, U32 maxSymbolValue, U32 huffLog)
|
106
90
|
{
|
107
91
|
BYTE bitsToWeight[HUF_TABLELOG_MAX + 1];
|
108
|
-
BYTE huffWeight[HUF_SYMBOLVALUE_MAX
|
109
|
-
U32 n;
|
92
|
+
BYTE huffWeight[HUF_SYMBOLVALUE_MAX];
|
110
93
|
BYTE* op = (BYTE*)dst;
|
111
|
-
|
94
|
+
U32 n;
|
112
95
|
|
113
96
|
/* check conditions */
|
114
|
-
if (maxSymbolValue > HUF_SYMBOLVALUE_MAX
|
115
|
-
return ERROR(GENERIC);
|
97
|
+
if (maxSymbolValue > HUF_SYMBOLVALUE_MAX) return ERROR(GENERIC);
|
116
98
|
|
117
99
|
/* convert to weight */
|
118
100
|
bitsToWeight[0] = 0;
|
119
|
-
for (n=1; n
|
101
|
+
for (n=1; n<huffLog+1; n++)
|
120
102
|
bitsToWeight[n] = (BYTE)(huffLog + 1 - n);
|
121
103
|
for (n=0; n<maxSymbolValue; n++)
|
122
104
|
huffWeight[n] = bitsToWeight[CTable[n].nbBits];
|
123
105
|
|
124
|
-
size = FSE_compress(op+1, maxDstSize-1, huffWeight, maxSymbolValue);
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
/* only possible case : series of 1 (because there are at least 2) */
|
130
|
-
/* can only be 2^n or (2^n-1), otherwise not an huffman tree */
|
131
|
-
BYTE code;
|
132
|
-
switch(maxSymbolValue)
|
133
|
-
{
|
134
|
-
case 1: code = 0; break;
|
135
|
-
case 2: code = 1; break;
|
136
|
-
case 3: code = 2; break;
|
137
|
-
case 4: code = 3; break;
|
138
|
-
case 7: code = 4; break;
|
139
|
-
case 8: code = 5; break;
|
140
|
-
case 15: code = 6; break;
|
141
|
-
case 16: code = 7; break;
|
142
|
-
case 31: code = 8; break;
|
143
|
-
case 32: code = 9; break;
|
144
|
-
case 63: code = 10; break;
|
145
|
-
case 64: code = 11; break;
|
146
|
-
case 127: code = 12; break;
|
147
|
-
case 128: code = 13; break;
|
148
|
-
default : return ERROR(corruption_detected);
|
149
|
-
}
|
150
|
-
op[0] = (BYTE)(255-13 + code);
|
151
|
-
return 1;
|
106
|
+
{ size_t const size = FSE_compress(op+1, maxDstSize-1, huffWeight, maxSymbolValue);
|
107
|
+
if (FSE_isError(size)) return size;
|
108
|
+
if ((size>1) & (size < maxSymbolValue/2)) { /* FSE compressed */
|
109
|
+
op[0] = (BYTE)size;
|
110
|
+
return size+1;
|
152
111
|
}
|
153
|
-
/* Not compressible */
|
154
|
-
if (maxSymbolValue > (241-128)) return ERROR(GENERIC); /* not implemented (not possible with current format) */
|
155
|
-
if (((maxSymbolValue+1)/2) + 1 > maxDstSize) return ERROR(dstSize_tooSmall); /* not enough space within dst buffer */
|
156
|
-
op[0] = (BYTE)(128 /*special case*/ + 0 /* Not Compressible */ + (maxSymbolValue-1));
|
157
|
-
huffWeight[maxSymbolValue] = 0; /* to be sure it doesn't cause issue in final combination */
|
158
|
-
for (n=0; n<maxSymbolValue; n+=2)
|
159
|
-
op[(n/2)+1] = (BYTE)((huffWeight[n] << 4) + huffWeight[n+1]);
|
160
|
-
return ((maxSymbolValue+1)/2) + 1;
|
161
112
|
}
|
162
113
|
|
163
|
-
/*
|
164
|
-
|
165
|
-
|
166
|
-
|
114
|
+
/* raw values */
|
115
|
+
if (maxSymbolValue > (256-128)) return ERROR(GENERIC); /* should not happen */
|
116
|
+
if (((maxSymbolValue+1)/2) + 1 > maxDstSize) return ERROR(dstSize_tooSmall); /* not enough space within dst buffer */
|
117
|
+
op[0] = (BYTE)(128 /*special case*/ + (maxSymbolValue-1));
|
118
|
+
huffWeight[maxSymbolValue] = 0; /* to be sure it doesn't cause issue in final combination */
|
119
|
+
for (n=0; n<maxSymbolValue; n+=2)
|
120
|
+
op[(n/2)+1] = (BYTE)((huffWeight[n] << 4) + huffWeight[n+1]);
|
121
|
+
return ((maxSymbolValue+1)/2) + 1;
|
167
122
|
|
123
|
+
}
|
168
124
|
|
169
125
|
|
170
126
|
size_t HUF_readCTable (HUF_CElt* CTable, U32 maxSymbolValue, const void* src, size_t srcSize)
|
@@ -174,7 +130,7 @@ size_t HUF_readCTable (HUF_CElt* CTable, U32 maxSymbolValue, const void* src, si
|
|
174
130
|
U32 tableLog = 0;
|
175
131
|
size_t readSize;
|
176
132
|
U32 nbSymbols = 0;
|
177
|
-
|
133
|
+
/*memset(huffWeight, 0, sizeof(huffWeight));*/ /* is not necessary, even though some analyzer complain ... */
|
178
134
|
|
179
135
|
/* get symbol weights */
|
180
136
|
readSize = HUF_readStats(huffWeight, HUF_SYMBOLVALUE_MAX+1, rankVal, &nbSymbols, &tableLog, src, srcSize);
|
@@ -193,19 +149,20 @@ size_t HUF_readCTable (HUF_CElt* CTable, U32 maxSymbolValue, const void* src, si
|
|
193
149
|
} }
|
194
150
|
|
195
151
|
/* fill nbBits */
|
196
|
-
{
|
197
|
-
|
198
|
-
|
199
|
-
}}
|
152
|
+
{ U32 n; for (n=0; n<nbSymbols; n++) {
|
153
|
+
const U32 w = huffWeight[n];
|
154
|
+
CTable[n].nbBits = (BYTE)(tableLog + 1 - w);
|
155
|
+
} }
|
200
156
|
|
201
157
|
/* fill val */
|
202
|
-
{ U16 nbPerRank[HUF_TABLELOG_MAX+
|
203
|
-
U16 valPerRank[HUF_TABLELOG_MAX+
|
158
|
+
{ U16 nbPerRank[HUF_TABLELOG_MAX+2] = {0}; /* support w=0=>n=tableLog+1 */
|
159
|
+
U16 valPerRank[HUF_TABLELOG_MAX+2] = {0};
|
204
160
|
{ U32 n; for (n=0; n<nbSymbols; n++) nbPerRank[CTable[n].nbBits]++; }
|
205
161
|
/* determine stating value per rank */
|
162
|
+
valPerRank[tableLog+1] = 0; /* for w==0 */
|
206
163
|
{ U16 min = 0;
|
207
|
-
U32 n; for (n=
|
208
|
-
valPerRank[n] = min;
|
164
|
+
U32 n; for (n=tableLog; n>0; n--) { /* start at n=tablelog <-> w=1 */
|
165
|
+
valPerRank[n] = min; /* get starting value within each rank */
|
209
166
|
min += nbPerRank[n];
|
210
167
|
min >>= 1;
|
211
168
|
} }
|
@@ -520,7 +477,7 @@ static size_t HUF_compress_internal (
|
|
520
477
|
/* Scan input and build symbol stats */
|
521
478
|
{ size_t const largest = FSE_count (count, &maxSymbolValue, (const BYTE*)src, srcSize);
|
522
479
|
if (HUF_isError(largest)) return largest;
|
523
|
-
if (largest == srcSize) { *ostart = ((const BYTE*)src)[0]; return 1; } /* rle */
|
480
|
+
if (largest == srcSize) { *ostart = ((const BYTE*)src)[0]; return 1; } /* single symbol, rle */
|
524
481
|
if (largest <= (srcSize >> 7)+1) return 0; /* Fast heuristic : not compressible enough */
|
525
482
|
}
|
526
483
|
|
@@ -535,7 +492,6 @@ static size_t HUF_compress_internal (
|
|
535
492
|
{ size_t const hSize = HUF_writeCTable (op, dstSize, CTable, maxSymbolValue, huffLog);
|
536
493
|
if (HUF_isError(hSize)) return hSize;
|
537
494
|
if (hSize + 12 >= srcSize) return 0; /* not useful to try compression */
|
538
|
-
//static U64 totalHSize = 0; static U32 nbHSize = 0; totalHSize += hSize; nbHSize++; if ((nbHSize & 63) == 1) printf("average : %6.3f \n", (double)totalHSize / nbHSize);
|
539
495
|
op += hSize;
|
540
496
|
}
|
541
497
|
|
@@ -1,33 +1,12 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
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
|
-
*/
|
1
|
+
/**
|
2
|
+
* Copyright (c) 2016-present, Yann Collet, Facebook, Inc.
|
3
|
+
* All rights reserved.
|
4
|
+
*
|
5
|
+
* This source code is licensed under the BSD-style license found in the
|
6
|
+
* LICENSE file in the root directory of this source tree. An additional grant
|
7
|
+
* of patent rights can be found in the PATENTS file in the same directory.
|
8
|
+
*/
|
9
|
+
|
31
10
|
|
32
11
|
|
33
12
|
/* *************************************
|
@@ -46,7 +25,7 @@
|
|
46
25
|
static size_t const ZBUFF_endFrameSize = ZSTD_BLOCKHEADERSIZE;
|
47
26
|
|
48
27
|
|
49
|
-
|
28
|
+
/*-***********************************************************
|
50
29
|
* Streaming compression
|
51
30
|
*
|
52
31
|
* A ZBUFF_CCtx object is required to track streaming operation.
|
@@ -77,7 +56,7 @@ static size_t const ZBUFF_endFrameSize = ZSTD_BLOCKHEADERSIZE;
|
|
77
56
|
* Hint : recommended buffer sizes (not compulsory)
|
78
57
|
* input : ZSTD_BLOCKSIZE_MAX (128 KB), internal unit size, it improves latency to use this value.
|
79
58
|
* output : ZSTD_compressBound(ZSTD_BLOCKSIZE_MAX) + ZSTD_blockHeaderSize + ZBUFF_endFrameSize : ensures it's always possible to write/flush/end a full block at best speed.
|
80
|
-
*
|
59
|
+
* ***********************************************************/
|
81
60
|
|
82
61
|
typedef enum { ZBUFFcs_init, ZBUFFcs_load, ZBUFFcs_flush, ZBUFFcs_final } ZBUFF_cStage;
|
83
62
|
|
@@ -95,8 +74,10 @@ struct ZBUFF_CCtx_s {
|
|
95
74
|
size_t outBuffContentSize;
|
96
75
|
size_t outBuffFlushedSize;
|
97
76
|
ZBUFF_cStage stage;
|
77
|
+
U32 checksum;
|
78
|
+
U32 frameEnded;
|
98
79
|
ZSTD_customMem customMem;
|
99
|
-
}; /* typedef'd tp ZBUFF_CCtx within "
|
80
|
+
}; /* typedef'd tp ZBUFF_CCtx within "zbuff.h" */
|
100
81
|
|
101
82
|
ZBUFF_CCtx* ZBUFF_createCCtx(void)
|
102
83
|
{
|
@@ -133,7 +114,7 @@ size_t ZBUFF_freeCCtx(ZBUFF_CCtx* zbc)
|
|
133
114
|
}
|
134
115
|
|
135
116
|
|
136
|
-
/*
|
117
|
+
/* ====== Initialization ====== */
|
137
118
|
|
138
119
|
size_t ZBUFF_compressInit_advanced(ZBUFF_CCtx* zbc,
|
139
120
|
const void* dict, size_t dictSize,
|
@@ -147,7 +128,7 @@ size_t ZBUFF_compressInit_advanced(ZBUFF_CCtx* zbc,
|
|
147
128
|
zbc->inBuff = (char*)zbc->customMem.customAlloc(zbc->customMem.opaque, neededInBuffSize);
|
148
129
|
if (zbc->inBuff == NULL) return ERROR(memory_allocation);
|
149
130
|
}
|
150
|
-
zbc->blockSize = MIN(
|
131
|
+
zbc->blockSize = MIN(ZSTD_BLOCKSIZE_ABSOLUTEMAX, neededInBuffSize);
|
151
132
|
}
|
152
133
|
if (zbc->outBuffSize < ZSTD_compressBound(zbc->blockSize)+1) {
|
153
134
|
zbc->outBuffSize = ZSTD_compressBound(zbc->blockSize)+1;
|
@@ -164,6 +145,8 @@ size_t ZBUFF_compressInit_advanced(ZBUFF_CCtx* zbc,
|
|
164
145
|
zbc->inBuffTarget = zbc->blockSize;
|
165
146
|
zbc->outBuffContentSize = zbc->outBuffFlushedSize = 0;
|
166
147
|
zbc->stage = ZBUFFcs_load;
|
148
|
+
zbc->checksum = params.fParams.checksumFlag > 0;
|
149
|
+
zbc->frameEnded = 0;
|
167
150
|
return 0; /* ready to go */
|
168
151
|
}
|
169
152
|
|
@@ -189,14 +172,16 @@ MEM_STATIC size_t ZBUFF_limitCopy(void* dst, size_t dstCapacity, const void* src
|
|
189
172
|
}
|
190
173
|
|
191
174
|
|
192
|
-
/*
|
175
|
+
/* ====== Compression ====== */
|
176
|
+
|
177
|
+
typedef enum { zbf_gather, zbf_flush, zbf_end } ZBUFF_flush_e;
|
193
178
|
|
194
179
|
static size_t ZBUFF_compressContinue_generic(ZBUFF_CCtx* zbc,
|
195
180
|
void* dst, size_t* dstCapacityPtr,
|
196
181
|
const void* src, size_t* srcSizePtr,
|
197
|
-
|
182
|
+
ZBUFF_flush_e const flush)
|
198
183
|
{
|
199
|
-
U32
|
184
|
+
U32 someMoreWork = 1;
|
200
185
|
const char* const istart = (const char*)src;
|
201
186
|
const char* const iend = istart + *srcSizePtr;
|
202
187
|
const char* ip = istart;
|
@@ -204,7 +189,7 @@ static size_t ZBUFF_compressContinue_generic(ZBUFF_CCtx* zbc,
|
|
204
189
|
char* const oend = ostart + *dstCapacityPtr;
|
205
190
|
char* op = ostart;
|
206
191
|
|
207
|
-
while (
|
192
|
+
while (someMoreWork) {
|
208
193
|
switch(zbc->stage)
|
209
194
|
{
|
210
195
|
case ZBUFFcs_init: return ERROR(init_missing); /* call ZBUFF_compressInit() first ! */
|
@@ -216,7 +201,7 @@ static size_t ZBUFF_compressContinue_generic(ZBUFF_CCtx* zbc,
|
|
216
201
|
zbc->inBuffPos += loaded;
|
217
202
|
ip += loaded;
|
218
203
|
if ( (zbc->inBuffPos==zbc->inToCompress) || (!flush && (toLoad != loaded)) ) {
|
219
|
-
|
204
|
+
someMoreWork = 0; break; /* not enough input to get a full block : stop there, wait for more */
|
220
205
|
} }
|
221
206
|
/* compress current block (note : this stage cannot be stopped in the middle) */
|
222
207
|
{ void* cDst;
|
@@ -227,8 +212,11 @@ static size_t ZBUFF_compressContinue_generic(ZBUFF_CCtx* zbc,
|
|
227
212
|
cDst = op; /* compress directly into output buffer (avoid flush stage) */
|
228
213
|
else
|
229
214
|
cDst = zbc->outBuff, oSize = zbc->outBuffSize;
|
230
|
-
cSize =
|
215
|
+
cSize = (flush == zbf_end) ?
|
216
|
+
ZSTD_compressEnd(zbc->zc, cDst, oSize, zbc->inBuff + zbc->inToCompress, iSize) :
|
217
|
+
ZSTD_compressContinue(zbc->zc, cDst, oSize, zbc->inBuff + zbc->inToCompress, iSize);
|
231
218
|
if (ZSTD_isError(cSize)) return cSize;
|
219
|
+
if (flush == zbf_end) zbc->frameEnded = 1;
|
232
220
|
/* prepare next block */
|
233
221
|
zbc->inBuffTarget = zbc->inBuffPos + zbc->blockSize;
|
234
222
|
if (zbc->inBuffTarget > zbc->inBuffSize)
|
@@ -245,14 +233,14 @@ static size_t ZBUFF_compressContinue_generic(ZBUFF_CCtx* zbc,
|
|
245
233
|
size_t const flushed = ZBUFF_limitCopy(op, oend-op, zbc->outBuff + zbc->outBuffFlushedSize, toFlush);
|
246
234
|
op += flushed;
|
247
235
|
zbc->outBuffFlushedSize += flushed;
|
248
|
-
if (toFlush!=flushed) {
|
236
|
+
if (toFlush!=flushed) { someMoreWork = 0; break; } /* dst too small to store flushed data : stop there */
|
249
237
|
zbc->outBuffContentSize = zbc->outBuffFlushedSize = 0;
|
250
238
|
zbc->stage = ZBUFFcs_load;
|
251
239
|
break;
|
252
240
|
}
|
253
241
|
|
254
242
|
case ZBUFFcs_final:
|
255
|
-
|
243
|
+
someMoreWork = 0; /* do nothing */
|
256
244
|
break;
|
257
245
|
|
258
246
|
default:
|
@@ -262,6 +250,7 @@ static size_t ZBUFF_compressContinue_generic(ZBUFF_CCtx* zbc,
|
|
262
250
|
|
263
251
|
*srcSizePtr = ip - istart;
|
264
252
|
*dstCapacityPtr = op - ostart;
|
253
|
+
if (zbc->frameEnded) return 0;
|
265
254
|
{ size_t hintInSize = zbc->inBuffTarget - zbc->inBuffPos;
|
266
255
|
if (hintInSize==0) hintInSize = zbc->blockSize;
|
267
256
|
return hintInSize;
|
@@ -272,17 +261,17 @@ size_t ZBUFF_compressContinue(ZBUFF_CCtx* zbc,
|
|
272
261
|
void* dst, size_t* dstCapacityPtr,
|
273
262
|
const void* src, size_t* srcSizePtr)
|
274
263
|
{
|
275
|
-
return ZBUFF_compressContinue_generic(zbc, dst, dstCapacityPtr, src, srcSizePtr,
|
264
|
+
return ZBUFF_compressContinue_generic(zbc, dst, dstCapacityPtr, src, srcSizePtr, zbf_gather);
|
276
265
|
}
|
277
266
|
|
278
267
|
|
279
268
|
|
280
|
-
/*
|
269
|
+
/* ====== Finalize ====== */
|
281
270
|
|
282
271
|
size_t ZBUFF_compressFlush(ZBUFF_CCtx* zbc, void* dst, size_t* dstCapacityPtr)
|
283
272
|
{
|
284
273
|
size_t srcSize = 0;
|
285
|
-
ZBUFF_compressContinue_generic(zbc, dst, dstCapacityPtr, &srcSize, &srcSize,
|
274
|
+
ZBUFF_compressContinue_generic(zbc, dst, dstCapacityPtr, &srcSize, &srcSize, zbf_flush); /* use a valid src address instead of NULL */
|
286
275
|
return zbc->outBuffContentSize - zbc->outBuffFlushedSize;
|
287
276
|
}
|
288
277
|
|
@@ -296,15 +285,18 @@ size_t ZBUFF_compressEnd(ZBUFF_CCtx* zbc, void* dst, size_t* dstCapacityPtr)
|
|
296
285
|
if (zbc->stage != ZBUFFcs_final) {
|
297
286
|
/* flush whatever remains */
|
298
287
|
size_t outSize = *dstCapacityPtr;
|
299
|
-
size_t
|
288
|
+
size_t srcSize = 0;
|
289
|
+
size_t const notEnded = ZBUFF_compressContinue_generic(zbc, dst, &outSize, &srcSize, &srcSize, zbf_end); /* use a valid address instead of NULL */
|
290
|
+
size_t const remainingToFlush = zbc->outBuffContentSize - zbc->outBuffFlushedSize;
|
300
291
|
op += outSize;
|
301
292
|
if (remainingToFlush) {
|
302
293
|
*dstCapacityPtr = op-ostart;
|
303
|
-
return remainingToFlush + ZBUFF_endFrameSize;
|
294
|
+
return remainingToFlush + ZBUFF_endFrameSize + (zbc->checksum * 4);
|
304
295
|
}
|
305
296
|
/* create epilogue */
|
306
297
|
zbc->stage = ZBUFFcs_final;
|
307
|
-
zbc->outBuffContentSize =
|
298
|
+
zbc->outBuffContentSize = !notEnded ? 0 :
|
299
|
+
ZSTD_compressEnd(zbc->zc, zbc->outBuff, zbc->outBuffSize, NULL, 0); /* write epilogue into outBuff */
|
308
300
|
}
|
309
301
|
|
310
302
|
/* flush epilogue */
|
@@ -323,5 +315,5 @@ size_t ZBUFF_compressEnd(ZBUFF_CCtx* zbc, void* dst, size_t* dstCapacityPtr)
|
|
323
315
|
/* *************************************
|
324
316
|
* Tool functions
|
325
317
|
***************************************/
|
326
|
-
size_t ZBUFF_recommendedCInSize(void) { return
|
327
|
-
size_t ZBUFF_recommendedCOutSize(void) { return ZSTD_compressBound(
|
318
|
+
size_t ZBUFF_recommendedCInSize(void) { return ZSTD_BLOCKSIZE_ABSOLUTEMAX; }
|
319
|
+
size_t ZBUFF_recommendedCOutSize(void) { return ZSTD_compressBound(ZSTD_BLOCKSIZE_ABSOLUTEMAX) + ZSTD_blockHeaderSize + ZBUFF_endFrameSize; }
|