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.
- checksums.yaml +5 -5
- data/HISTORY.ja.md +39 -0
- data/LICENSE +6 -6
- data/README.md +26 -45
- data/contrib/zstd/CHANGELOG +555 -0
- data/contrib/zstd/CODE_OF_CONDUCT.md +5 -0
- data/contrib/zstd/CONTRIBUTING.md +392 -0
- data/contrib/zstd/COPYING +339 -0
- data/contrib/zstd/LICENSE +13 -9
- data/contrib/zstd/Makefile +414 -0
- data/contrib/zstd/README.md +170 -45
- data/contrib/zstd/TESTING.md +44 -0
- data/contrib/zstd/appveyor.yml +289 -0
- data/contrib/zstd/lib/BUCK +234 -0
- data/contrib/zstd/lib/Makefile +354 -0
- data/contrib/zstd/lib/README.md +179 -0
- data/contrib/zstd/{common → lib/common}/bitstream.h +170 -130
- data/contrib/zstd/lib/common/compiler.h +175 -0
- data/contrib/zstd/lib/common/cpu.h +215 -0
- data/contrib/zstd/lib/common/debug.c +24 -0
- data/contrib/zstd/lib/common/debug.h +114 -0
- data/contrib/zstd/{common → lib/common}/entropy_common.c +79 -94
- data/contrib/zstd/lib/common/error_private.c +55 -0
- data/contrib/zstd/lib/common/error_private.h +80 -0
- data/contrib/zstd/{common → lib/common}/fse.h +153 -93
- data/contrib/zstd/{common → lib/common}/fse_decompress.c +37 -82
- data/contrib/zstd/lib/common/huf.h +340 -0
- data/contrib/zstd/{common → lib/common}/mem.h +154 -78
- data/contrib/zstd/lib/common/pool.c +344 -0
- data/contrib/zstd/lib/common/pool.h +84 -0
- data/contrib/zstd/lib/common/threading.c +121 -0
- data/contrib/zstd/lib/common/threading.h +155 -0
- data/contrib/zstd/{common → lib/common}/xxhash.c +85 -75
- data/contrib/zstd/{common → lib/common}/xxhash.h +85 -73
- data/contrib/zstd/lib/common/zstd_common.c +83 -0
- data/contrib/zstd/lib/common/zstd_errors.h +94 -0
- data/contrib/zstd/lib/common/zstd_internal.h +447 -0
- data/contrib/zstd/{compress → lib/compress}/fse_compress.c +194 -303
- data/contrib/zstd/lib/compress/hist.c +183 -0
- data/contrib/zstd/lib/compress/hist.h +75 -0
- data/contrib/zstd/lib/compress/huf_compress.c +798 -0
- data/contrib/zstd/lib/compress/zstd_compress.c +4278 -0
- data/contrib/zstd/lib/compress/zstd_compress_internal.h +1125 -0
- data/contrib/zstd/lib/compress/zstd_compress_literals.c +158 -0
- data/contrib/zstd/lib/compress/zstd_compress_literals.h +29 -0
- data/contrib/zstd/lib/compress/zstd_compress_sequences.c +419 -0
- data/contrib/zstd/lib/compress/zstd_compress_sequences.h +54 -0
- data/contrib/zstd/lib/compress/zstd_compress_superblock.c +845 -0
- data/contrib/zstd/lib/compress/zstd_compress_superblock.h +32 -0
- data/contrib/zstd/lib/compress/zstd_cwksp.h +525 -0
- data/contrib/zstd/lib/compress/zstd_double_fast.c +521 -0
- data/contrib/zstd/lib/compress/zstd_double_fast.h +38 -0
- data/contrib/zstd/lib/compress/zstd_fast.c +496 -0
- data/contrib/zstd/lib/compress/zstd_fast.h +37 -0
- data/contrib/zstd/lib/compress/zstd_lazy.c +1138 -0
- data/contrib/zstd/lib/compress/zstd_lazy.h +67 -0
- data/contrib/zstd/lib/compress/zstd_ldm.c +619 -0
- data/contrib/zstd/lib/compress/zstd_ldm.h +110 -0
- data/contrib/zstd/lib/compress/zstd_opt.c +1200 -0
- data/contrib/zstd/lib/compress/zstd_opt.h +56 -0
- data/contrib/zstd/lib/compress/zstdmt_compress.c +2143 -0
- data/contrib/zstd/lib/compress/zstdmt_compress.h +192 -0
- data/contrib/zstd/lib/decompress/huf_decompress.c +1248 -0
- data/contrib/zstd/lib/decompress/zstd_ddict.c +244 -0
- data/contrib/zstd/lib/decompress/zstd_ddict.h +44 -0
- data/contrib/zstd/lib/decompress/zstd_decompress.c +1885 -0
- data/contrib/zstd/lib/decompress/zstd_decompress_block.c +1432 -0
- data/contrib/zstd/lib/decompress/zstd_decompress_block.h +59 -0
- data/contrib/zstd/lib/decompress/zstd_decompress_internal.h +189 -0
- data/contrib/zstd/{common → lib/deprecated}/zbuff.h +86 -69
- data/contrib/zstd/lib/deprecated/zbuff_common.c +26 -0
- data/contrib/zstd/lib/deprecated/zbuff_compress.c +147 -0
- data/contrib/zstd/lib/deprecated/zbuff_decompress.c +75 -0
- data/contrib/zstd/lib/dictBuilder/cover.c +1236 -0
- data/contrib/zstd/lib/dictBuilder/cover.h +157 -0
- data/contrib/zstd/{dictBuilder → lib/dictBuilder}/divsufsort.c +3 -3
- data/contrib/zstd/{dictBuilder → lib/dictBuilder}/divsufsort.h +5 -5
- data/contrib/zstd/lib/dictBuilder/fastcover.c +757 -0
- data/contrib/zstd/{dictBuilder → lib/dictBuilder}/zdict.c +437 -347
- data/contrib/zstd/lib/dictBuilder/zdict.h +305 -0
- data/contrib/zstd/lib/legacy/zstd_legacy.h +415 -0
- data/contrib/zstd/{legacy → lib/legacy}/zstd_v01.c +272 -292
- data/contrib/zstd/{legacy → lib/legacy}/zstd_v01.h +26 -32
- data/contrib/zstd/{legacy → lib/legacy}/zstd_v02.c +162 -392
- data/contrib/zstd/{legacy → lib/legacy}/zstd_v02.h +26 -32
- data/contrib/zstd/{legacy → lib/legacy}/zstd_v03.c +162 -391
- data/contrib/zstd/{legacy → lib/legacy}/zstd_v03.h +27 -33
- data/contrib/zstd/{legacy → lib/legacy}/zstd_v04.c +195 -604
- data/contrib/zstd/{legacy → lib/legacy}/zstd_v04.h +26 -32
- data/contrib/zstd/{legacy → lib/legacy}/zstd_v05.c +300 -575
- data/contrib/zstd/{legacy → lib/legacy}/zstd_v05.h +22 -31
- data/contrib/zstd/{legacy → lib/legacy}/zstd_v06.c +165 -592
- data/contrib/zstd/{legacy → lib/legacy}/zstd_v06.h +54 -67
- data/contrib/zstd/lib/legacy/zstd_v07.c +4541 -0
- data/contrib/zstd/lib/legacy/zstd_v07.h +187 -0
- data/contrib/zstd/lib/libzstd.pc.in +15 -0
- data/contrib/zstd/lib/zstd.h +2090 -0
- data/ext/depend +2 -0
- data/ext/extconf.rb +18 -5
- data/ext/extzstd.c +296 -214
- data/ext/extzstd.h +81 -36
- data/ext/extzstd_nogvls.h +0 -117
- data/ext/extzstd_stream.c +622 -0
- data/ext/libzstd_conf.h +8 -0
- data/ext/zstd_common.c +11 -0
- data/ext/zstd_compress.c +15 -0
- data/ext/zstd_decompress.c +6 -0
- data/ext/zstd_dictbuilder.c +10 -0
- data/ext/zstd_dictbuilder_fastcover.c +3 -0
- data/ext/zstd_legacy_v01.c +3 -1
- data/ext/zstd_legacy_v02.c +3 -1
- data/ext/zstd_legacy_v03.c +3 -1
- data/ext/zstd_legacy_v04.c +3 -1
- data/ext/zstd_legacy_v05.c +3 -1
- data/ext/zstd_legacy_v06.c +3 -1
- data/ext/zstd_legacy_v07.c +3 -0
- data/gemstub.rb +27 -21
- data/lib/extzstd.rb +82 -161
- data/lib/extzstd/version.rb +1 -1
- data/test/test_basic.rb +19 -6
- metadata +127 -59
- data/contrib/zstd/common/error_private.h +0 -125
- data/contrib/zstd/common/error_public.h +0 -77
- data/contrib/zstd/common/huf.h +0 -228
- data/contrib/zstd/common/zstd.h +0 -475
- data/contrib/zstd/common/zstd_common.c +0 -91
- data/contrib/zstd/common/zstd_internal.h +0 -238
- data/contrib/zstd/compress/huf_compress.c +0 -577
- data/contrib/zstd/compress/zbuff_compress.c +0 -327
- data/contrib/zstd/compress/zstd_compress.c +0 -3074
- data/contrib/zstd/compress/zstd_opt.h +0 -1046
- data/contrib/zstd/decompress/huf_decompress.c +0 -894
- data/contrib/zstd/decompress/zbuff_decompress.c +0 -294
- data/contrib/zstd/decompress/zstd_decompress.c +0 -1362
- data/contrib/zstd/dictBuilder/zdict.h +0 -113
- data/contrib/zstd/legacy/zstd_legacy.h +0 -140
- data/ext/extzstd_buffered.c +0 -265
- data/ext/zstd_amalgam.c +0 -18
@@ -1,113 +0,0 @@
|
|
1
|
-
/*
|
2
|
-
dictBuilder header file
|
3
|
-
Copyright (C) Yann Collet 2016
|
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
|
-
|
11
|
-
* Redistributions of source code must retain the above copyright
|
12
|
-
notice, this list of conditions and the following disclaimer.
|
13
|
-
* Redistributions in binary form must reproduce the above
|
14
|
-
copyright notice, this list of conditions and the following disclaimer
|
15
|
-
in the documentation and/or other materials provided with the
|
16
|
-
distribution.
|
17
|
-
|
18
|
-
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
19
|
-
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
20
|
-
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
21
|
-
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
22
|
-
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
23
|
-
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
24
|
-
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
25
|
-
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
26
|
-
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
27
|
-
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
28
|
-
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
29
|
-
|
30
|
-
You can contact the author at :
|
31
|
-
- Zstd source repository : https://www.zstd.net
|
32
|
-
*/
|
33
|
-
|
34
|
-
#ifndef DICTBUILDER_H_001
|
35
|
-
#define DICTBUILDER_H_001
|
36
|
-
|
37
|
-
#if defined (__cplusplus)
|
38
|
-
extern "C" {
|
39
|
-
#endif
|
40
|
-
|
41
|
-
/*-*************************************
|
42
|
-
* Public functions
|
43
|
-
***************************************/
|
44
|
-
/*! ZDICT_trainFromBuffer() :
|
45
|
-
Train a dictionary from a memory buffer `samplesBuffer`,
|
46
|
-
where `nbSamples` samples have been stored concatenated.
|
47
|
-
Each sample size is provided into an orderly table `samplesSizes`.
|
48
|
-
Resulting dictionary will be saved into `dictBuffer`.
|
49
|
-
@return : size of dictionary stored into `dictBuffer` (<= `dictBufferCapacity`)
|
50
|
-
or an error code, which can be tested by ZDICT_isError().
|
51
|
-
*/
|
52
|
-
size_t ZDICT_trainFromBuffer(void* dictBuffer, size_t dictBufferCapacity,
|
53
|
-
const void* samplesBuffer, const size_t* samplesSizes, unsigned nbSamples);
|
54
|
-
|
55
|
-
/*! ZDICT_addEntropyTablesFromBuffer() :
|
56
|
-
|
57
|
-
Given a content-only dictionary (built for example from common strings in
|
58
|
-
the input), add entropy tables computed from the memory buffer
|
59
|
-
`samplesBuffer`, where `nbSamples` samples have been stored concatenated.
|
60
|
-
Each sample size is provided into an orderly table `samplesSizes`.
|
61
|
-
|
62
|
-
The input dictionary is the last `dictContentSize` bytes of `dictBuffer`. The
|
63
|
-
resulting dictionary with added entropy tables will written back to
|
64
|
-
`dictBuffer`.
|
65
|
-
@return : size of dictionary stored into `dictBuffer` (<= `dictBufferCapacity`).
|
66
|
-
*/
|
67
|
-
size_t ZDICT_addEntropyTablesFromBuffer(void* dictBuffer, size_t dictContentSize, size_t dictBufferCapacity,
|
68
|
-
const void* samplesBuffer, const size_t* samplesSizes, unsigned nbSamples);
|
69
|
-
|
70
|
-
|
71
|
-
/*-*************************************
|
72
|
-
* Helper functions
|
73
|
-
***************************************/
|
74
|
-
unsigned ZDICT_isError(size_t errorCode);
|
75
|
-
const char* ZDICT_getErrorName(size_t errorCode);
|
76
|
-
|
77
|
-
|
78
|
-
#ifdef ZDICT_STATIC_LINKING_ONLY
|
79
|
-
|
80
|
-
/* ====================================================================================
|
81
|
-
* The definitions in this section are considered experimental.
|
82
|
-
* They should never be used with a dynamic library, as they may change in the future.
|
83
|
-
* They are provided for advanced usages.
|
84
|
-
* Use them only in association with static linking.
|
85
|
-
* ==================================================================================== */
|
86
|
-
|
87
|
-
typedef struct {
|
88
|
-
unsigned selectivityLevel; /* 0 means default; larger => bigger selection => larger dictionary */
|
89
|
-
unsigned compressionLevel; /* 0 means default; target a specific zstd compression level */
|
90
|
-
unsigned notificationLevel; /* Write to stderr; 0 = none (default); 1 = errors; 2 = progression; 3 = details; 4 = debug; */
|
91
|
-
unsigned dictID; /* 0 means auto mode (32-bits random value); other : force dictID value */
|
92
|
-
unsigned reserved[2]; /* space for future parameters */
|
93
|
-
} ZDICT_params_t;
|
94
|
-
|
95
|
-
|
96
|
-
/*! ZDICT_trainFromBuffer_advanced() :
|
97
|
-
Same as ZDICT_trainFromBuffer() with control over more parameters.
|
98
|
-
`parameters` is optional and can be provided with values set to 0 to mean "default".
|
99
|
-
@return : size of dictionary stored into `dictBuffer` (<= `dictBufferSize`)
|
100
|
-
or an error code, which can be tested by ZDICT_isError().
|
101
|
-
note : ZDICT_trainFromBuffer_advanced() will send notifications into stderr if instructed to, using ZDICT_setNotificationLevel()
|
102
|
-
*/
|
103
|
-
size_t ZDICT_trainFromBuffer_advanced(void* dictBuffer, size_t dictBufferCapacity,
|
104
|
-
const void* samplesBuffer, const size_t* samplesSizes, unsigned nbSamples,
|
105
|
-
ZDICT_params_t parameters);
|
106
|
-
|
107
|
-
#endif /* ZDICT_STATIC_LINKING_ONLY */
|
108
|
-
|
109
|
-
#if defined (__cplusplus)
|
110
|
-
}
|
111
|
-
#endif
|
112
|
-
|
113
|
-
#endif /* DICTBUILDER_H_001 */
|
@@ -1,140 +0,0 @@
|
|
1
|
-
/*
|
2
|
-
zstd_legacy - decoder for legacy format
|
3
|
-
Header File
|
4
|
-
Copyright (C) 2015-2016, Yann Collet.
|
5
|
-
|
6
|
-
BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
|
7
|
-
|
8
|
-
Redistribution and use in source and binary forms, with or without
|
9
|
-
modification, are permitted provided that the following conditions are
|
10
|
-
met:
|
11
|
-
* Redistributions of source code must retain the above copyright
|
12
|
-
notice, this list of conditions and the following disclaimer.
|
13
|
-
* Redistributions in binary form must reproduce the above
|
14
|
-
copyright notice, this list of conditions and the following disclaimer
|
15
|
-
in the documentation and/or other materials provided with the
|
16
|
-
distribution.
|
17
|
-
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
18
|
-
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
19
|
-
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
20
|
-
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
21
|
-
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
22
|
-
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
23
|
-
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
24
|
-
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
25
|
-
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
26
|
-
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
27
|
-
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
28
|
-
|
29
|
-
You can contact the author at :
|
30
|
-
- zstd source repository : https://github.com/Cyan4973/zstd
|
31
|
-
- ztsd public forum : https://groups.google.com/forum/#!forum/lz4c
|
32
|
-
*/
|
33
|
-
#ifndef ZSTD_LEGACY_H
|
34
|
-
#define ZSTD_LEGACY_H
|
35
|
-
|
36
|
-
#if defined (__cplusplus)
|
37
|
-
extern "C" {
|
38
|
-
#endif
|
39
|
-
|
40
|
-
/* *************************************
|
41
|
-
* Includes
|
42
|
-
***************************************/
|
43
|
-
#include "mem.h" /* MEM_STATIC */
|
44
|
-
#include "error_private.h" /* ERROR */
|
45
|
-
#include "zstd_v01.h"
|
46
|
-
#include "zstd_v02.h"
|
47
|
-
#include "zstd_v03.h"
|
48
|
-
#include "zstd_v04.h"
|
49
|
-
#include "zstd_v05.h"
|
50
|
-
#include "zstd_v06.h"
|
51
|
-
|
52
|
-
|
53
|
-
/** ZSTD_isLegacy() :
|
54
|
-
@return : > 0 if supported by legacy decoder. 0 otherwise.
|
55
|
-
return value is the version.
|
56
|
-
*/
|
57
|
-
MEM_STATIC unsigned ZSTD_isLegacy(const void* src, size_t srcSize)
|
58
|
-
{
|
59
|
-
U32 magicNumberLE;
|
60
|
-
if (srcSize<4) return 0;
|
61
|
-
magicNumberLE = MEM_readLE32(src);
|
62
|
-
switch(magicNumberLE)
|
63
|
-
{
|
64
|
-
case ZSTDv01_magicNumberLE:return 1;
|
65
|
-
case ZSTDv02_magicNumber : return 2;
|
66
|
-
case ZSTDv03_magicNumber : return 3;
|
67
|
-
case ZSTDv04_magicNumber : return 4;
|
68
|
-
case ZSTDv05_MAGICNUMBER : return 5;
|
69
|
-
case ZSTDv06_MAGICNUMBER : return 6;
|
70
|
-
default : return 0;
|
71
|
-
}
|
72
|
-
}
|
73
|
-
|
74
|
-
|
75
|
-
MEM_STATIC unsigned long long ZSTD_getDecompressedSize_legacy(const void* src, size_t srcSize)
|
76
|
-
{
|
77
|
-
if (srcSize < 4) return 0;
|
78
|
-
|
79
|
-
{ U32 const version = ZSTD_isLegacy(src, srcSize);
|
80
|
-
if (version < 5) return 0; /* no decompressed size in frame header, or not a legacy format */
|
81
|
-
if (version==5) {
|
82
|
-
ZSTDv05_parameters fParams;
|
83
|
-
size_t const frResult = ZSTDv05_getFrameParams(&fParams, src, srcSize);
|
84
|
-
if (frResult != 0) return 0;
|
85
|
-
return fParams.srcSize;
|
86
|
-
}
|
87
|
-
if (version==6) {
|
88
|
-
ZSTDv06_frameParams fParams;
|
89
|
-
size_t const frResult = ZSTDv06_getFrameParams(&fParams, src, srcSize);
|
90
|
-
if (frResult != 0) return 0;
|
91
|
-
return fParams.frameContentSize;
|
92
|
-
}
|
93
|
-
return 0; /* should not be possible */
|
94
|
-
}
|
95
|
-
}
|
96
|
-
|
97
|
-
MEM_STATIC size_t ZSTD_decompressLegacy(
|
98
|
-
void* dst, size_t dstCapacity,
|
99
|
-
const void* src, size_t compressedSize,
|
100
|
-
const void* dict,size_t dictSize)
|
101
|
-
{
|
102
|
-
U32 const version = ZSTD_isLegacy(src, compressedSize);
|
103
|
-
switch(version)
|
104
|
-
{
|
105
|
-
case 1 :
|
106
|
-
return ZSTDv01_decompress(dst, dstCapacity, src, compressedSize);
|
107
|
-
case 2 :
|
108
|
-
return ZSTDv02_decompress(dst, dstCapacity, src, compressedSize);
|
109
|
-
case 3 :
|
110
|
-
return ZSTDv03_decompress(dst, dstCapacity, src, compressedSize);
|
111
|
-
case 4 :
|
112
|
-
return ZSTDv04_decompress(dst, dstCapacity, src, compressedSize);
|
113
|
-
case 5 :
|
114
|
-
{ size_t result;
|
115
|
-
ZSTDv05_DCtx* const zd = ZSTDv05_createDCtx();
|
116
|
-
if (zd==NULL) return ERROR(memory_allocation);
|
117
|
-
result = ZSTDv05_decompress_usingDict(zd, dst, dstCapacity, src, compressedSize, dict, dictSize);
|
118
|
-
ZSTDv05_freeDCtx(zd);
|
119
|
-
return result;
|
120
|
-
}
|
121
|
-
case 6 :
|
122
|
-
{ size_t result;
|
123
|
-
ZSTDv06_DCtx* const zd = ZSTDv06_createDCtx();
|
124
|
-
if (zd==NULL) return ERROR(memory_allocation);
|
125
|
-
result = ZSTDv06_decompress_usingDict(zd, dst, dstCapacity, src, compressedSize, dict, dictSize);
|
126
|
-
ZSTDv06_freeDCtx(zd);
|
127
|
-
return result;
|
128
|
-
}
|
129
|
-
default :
|
130
|
-
return ERROR(prefix_unknown);
|
131
|
-
}
|
132
|
-
}
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
#if defined (__cplusplus)
|
137
|
-
}
|
138
|
-
#endif
|
139
|
-
|
140
|
-
#endif /* ZSTD_LEGACY_H */
|
data/ext/extzstd_buffered.c
DELETED
@@ -1,265 +0,0 @@
|
|
1
|
-
#include "extzstd.h"
|
2
|
-
#include "extzstd_nogvls.h"
|
3
|
-
|
4
|
-
/*
|
5
|
-
* class Zstd::BufferedEncoder
|
6
|
-
*/
|
7
|
-
|
8
|
-
static void
|
9
|
-
bufenc_free(void *p)
|
10
|
-
{
|
11
|
-
ZBUFF_freeCCtx(p);
|
12
|
-
}
|
13
|
-
|
14
|
-
AUX_IMPLEMENT_CONTEXT(
|
15
|
-
ZBUFF_CCtx, bufenc_datatype, "extzstd.BufferedEncoder",
|
16
|
-
bufenc_alloc_dummy, NULL, bufenc_free, NULL,
|
17
|
-
getbufencp, getbufenc, bufenc_p);
|
18
|
-
|
19
|
-
static VALUE
|
20
|
-
bufenc_alloc(VALUE mod)
|
21
|
-
{
|
22
|
-
ZBUFF_CCtx *p = ZBUFF_createCCtx();
|
23
|
-
if (!p) {
|
24
|
-
rb_gc();
|
25
|
-
p = ZBUFF_createCCtx();
|
26
|
-
if (!p) {
|
27
|
-
rb_raise(extzstd_eError, "failed ZBUFF_createCCtx()");
|
28
|
-
}
|
29
|
-
}
|
30
|
-
|
31
|
-
return TypedData_Wrap_Struct(mod, &bufenc_datatype, p);
|
32
|
-
}
|
33
|
-
|
34
|
-
static VALUE
|
35
|
-
bufenc_init(VALUE enc, VALUE params, VALUE dict)
|
36
|
-
{
|
37
|
-
ZBUFF_CCtx *p = getbufenc(enc);
|
38
|
-
const void *dictp;
|
39
|
-
size_t dictsize;
|
40
|
-
if (NIL_P(dict)) {
|
41
|
-
dictp = NULL;
|
42
|
-
dictsize = 0;
|
43
|
-
} else {
|
44
|
-
rb_check_type(dict, RUBY_T_STRING);
|
45
|
-
RSTRING_GETMEM(dict, dictp, dictsize);
|
46
|
-
}
|
47
|
-
if (extzstd_encparams_p(params)) {
|
48
|
-
ZSTD_parameters *paramsp = extzstd_getencparams(params);
|
49
|
-
size_t s = aux_ZBUFF_compressInit_advanced(p, dictp, dictsize, paramsp, 0);
|
50
|
-
extzstd_check_error(s);
|
51
|
-
} else {
|
52
|
-
size_t s = aux_ZBUFF_compressInitDictionary(p, dictp, dictsize, aux_num2int(params, 1));
|
53
|
-
extzstd_check_error(s);
|
54
|
-
}
|
55
|
-
|
56
|
-
return enc;
|
57
|
-
}
|
58
|
-
|
59
|
-
static VALUE
|
60
|
-
bufenc_continue(VALUE v, VALUE src, VALUE srcoff, VALUE dest, VALUE maxsize)
|
61
|
-
{
|
62
|
-
ZBUFF_CCtx *p = getbufenc(v);
|
63
|
-
rb_check_type(src, RUBY_T_STRING);
|
64
|
-
char *srcp;
|
65
|
-
size_t srcsize;
|
66
|
-
RSTRING_GETMEM(src, srcp, srcsize);
|
67
|
-
size_t srcoff1 = NUM2SIZET(srcoff);
|
68
|
-
if ((srcsize > 0 && srcoff1 >= srcsize) || srcoff1 > srcsize) {
|
69
|
-
rb_raise(rb_eArgError,
|
70
|
-
"``srcoff'' is out of src size (%"PRIuSIZE" for 0...%"PRIuSIZE")",
|
71
|
-
srcoff1, srcsize);
|
72
|
-
}
|
73
|
-
srcp += srcoff1;
|
74
|
-
srcsize -= srcoff1;
|
75
|
-
size_t destsize = NUM2SIZET(maxsize);
|
76
|
-
rb_check_type(dest, RUBY_T_STRING);
|
77
|
-
aux_str_modify_expand(dest, destsize);
|
78
|
-
rb_obj_infect(v, src);
|
79
|
-
rb_obj_infect(dest, v);
|
80
|
-
size_t s = aux_ZBUFF_compressContinue(p, RSTRING_PTR(dest), &destsize, srcp, &srcsize);
|
81
|
-
extzstd_check_error(s);
|
82
|
-
rb_str_set_len(dest, destsize);
|
83
|
-
if (srcsize > 0) {
|
84
|
-
return SIZET2NUM(srcoff1 + srcsize);
|
85
|
-
} else {
|
86
|
-
return Qnil;
|
87
|
-
}
|
88
|
-
}
|
89
|
-
|
90
|
-
static VALUE
|
91
|
-
bufenc_flush(VALUE v, VALUE dest, VALUE maxsize)
|
92
|
-
{
|
93
|
-
ZBUFF_CCtx *p = getbufenc(v);
|
94
|
-
size_t destsize = NUM2SIZET(maxsize);
|
95
|
-
rb_check_type(dest, RUBY_T_STRING);
|
96
|
-
aux_str_modify_expand(dest, destsize);
|
97
|
-
size_t s = aux_ZBUFF_compressFlush(p, RSTRING_PTR(dest), &destsize);
|
98
|
-
extzstd_check_error(s);
|
99
|
-
rb_str_set_len(dest, destsize);
|
100
|
-
return dest;
|
101
|
-
}
|
102
|
-
|
103
|
-
static VALUE
|
104
|
-
bufenc_end(VALUE v, VALUE dest, VALUE maxsize)
|
105
|
-
{
|
106
|
-
ZBUFF_CCtx *p = getbufenc(v);
|
107
|
-
size_t destsize = NUM2SIZET(maxsize);
|
108
|
-
rb_check_type(dest, RUBY_T_STRING);
|
109
|
-
aux_str_modify_expand(dest, destsize);
|
110
|
-
size_t s = aux_ZBUFF_compressEnd(p, RSTRING_PTR(dest), &destsize);
|
111
|
-
extzstd_check_error(s);
|
112
|
-
rb_str_set_len(dest, destsize);
|
113
|
-
return dest;
|
114
|
-
}
|
115
|
-
|
116
|
-
static VALUE
|
117
|
-
bufenc_s_recommended_insize(VALUE mod)
|
118
|
-
{
|
119
|
-
return SIZET2NUM(ZBUFF_recommendedCInSize());
|
120
|
-
}
|
121
|
-
|
122
|
-
static VALUE
|
123
|
-
bufenc_s_recommended_outsize(VALUE mod)
|
124
|
-
{
|
125
|
-
return SIZET2NUM(ZBUFF_recommendedCOutSize());
|
126
|
-
}
|
127
|
-
|
128
|
-
static void
|
129
|
-
init_buffered_encoder(void)
|
130
|
-
{
|
131
|
-
VALUE cBufEncoder = rb_define_class_under(extzstd_mZstd, "BufferedEncoder", rb_cObject);
|
132
|
-
rb_define_alloc_func(cBufEncoder, bufenc_alloc);
|
133
|
-
rb_define_method(cBufEncoder, "initialize", RUBY_METHOD_FUNC(bufenc_init), 2);
|
134
|
-
rb_define_method(cBufEncoder, "continue", RUBY_METHOD_FUNC(bufenc_continue), 4);
|
135
|
-
rb_define_method(cBufEncoder, "flush", RUBY_METHOD_FUNC(bufenc_flush), 2);
|
136
|
-
rb_define_method(cBufEncoder, "end", RUBY_METHOD_FUNC(bufenc_end), 2);
|
137
|
-
rb_define_singleton_method(cBufEncoder, "recommended_insize", RUBY_METHOD_FUNC(bufenc_s_recommended_insize), 0);
|
138
|
-
rb_define_singleton_method(cBufEncoder, "recommended_outsize", RUBY_METHOD_FUNC(bufenc_s_recommended_outsize), 0);
|
139
|
-
}
|
140
|
-
|
141
|
-
/*
|
142
|
-
* class Zstd::BufferedDecoder
|
143
|
-
*/
|
144
|
-
|
145
|
-
static void
|
146
|
-
bufdec_free(void *p)
|
147
|
-
{
|
148
|
-
ZBUFF_freeDCtx(p);
|
149
|
-
}
|
150
|
-
|
151
|
-
AUX_IMPLEMENT_CONTEXT(
|
152
|
-
ZBUFF_DCtx, bufdec_datatype, "extzstd.BufferedDecoder",
|
153
|
-
bufdec_alloc_dummy, NULL, bufdec_free, NULL,
|
154
|
-
getbufdecp, getbufdec, bufdec_p);
|
155
|
-
|
156
|
-
static VALUE
|
157
|
-
bufdec_alloc(VALUE mod)
|
158
|
-
{
|
159
|
-
ZBUFF_DCtx *p = ZBUFF_createDCtx();
|
160
|
-
if (!p) {
|
161
|
-
rb_gc();
|
162
|
-
p = ZBUFF_createDCtx();
|
163
|
-
if (!p) {
|
164
|
-
rb_raise(extzstd_eError, "failed ZBUFF_createDCtx()");
|
165
|
-
}
|
166
|
-
}
|
167
|
-
|
168
|
-
return TypedData_Wrap_Struct(mod, &bufdec_datatype, p);
|
169
|
-
}
|
170
|
-
|
171
|
-
static VALUE
|
172
|
-
bufdec_init(VALUE dec, VALUE dict)
|
173
|
-
{
|
174
|
-
/*
|
175
|
-
* ZSTDLIB_API size_t ZBUFF_decompressInitDictionary(ZBUFF_DCtx* dctx, const void* dict, size_t dictSize);
|
176
|
-
*/
|
177
|
-
|
178
|
-
ZBUFF_DCtx *p = getbufdec(dec);
|
179
|
-
if (!NIL_P(dict)) {
|
180
|
-
rb_check_type(dict, RUBY_T_STRING);
|
181
|
-
if (RSTRING_LEN(dict) > 0) {
|
182
|
-
dict = rb_str_new_frozen(dict);
|
183
|
-
rb_obj_infect(dec, dict);
|
184
|
-
size_t s = ZBUFF_decompressInitDictionary(p, RSTRING_PTR(dict), RSTRING_LEN(dict));
|
185
|
-
extzstd_check_error(s);
|
186
|
-
rb_iv_set(dec, "extzstd.dictionary for gc-guard", dict);
|
187
|
-
return dec;
|
188
|
-
}
|
189
|
-
}
|
190
|
-
|
191
|
-
size_t s = aux_ZBUFF_decompressInit(p);
|
192
|
-
extzstd_check_error(s);
|
193
|
-
|
194
|
-
return dec;
|
195
|
-
}
|
196
|
-
|
197
|
-
/*
|
198
|
-
* call-seq:
|
199
|
-
* continue(src, srcoff, dest, maxdestsize) -> srcoff or nil
|
200
|
-
*/
|
201
|
-
static VALUE
|
202
|
-
bufdec_continue(VALUE dec, VALUE src, VALUE srcoff, VALUE dest, VALUE maxdest)
|
203
|
-
{
|
204
|
-
ZBUFF_DCtx *p = getbufdec(dec);
|
205
|
-
rb_check_type(src, RUBY_T_STRING);
|
206
|
-
rb_check_type(dest, RUBY_T_STRING);
|
207
|
-
const char *srcp;
|
208
|
-
size_t srcsize;
|
209
|
-
RSTRING_GETMEM(src, srcp, srcsize);
|
210
|
-
size_t srcoff1 = NUM2SIZET(srcoff);
|
211
|
-
if (srcoff1 >= srcsize) {
|
212
|
-
rb_raise(rb_eArgError,
|
213
|
-
"``srcoff'' is out of src size (%"PRIuSIZE" for 0...%"PRIuSIZE")",
|
214
|
-
srcoff1, srcsize);
|
215
|
-
}
|
216
|
-
srcp += srcoff1;
|
217
|
-
srcsize -= srcoff1;
|
218
|
-
size_t destsize = NUM2SIZET(maxdest);
|
219
|
-
aux_str_modify_expand(dest, destsize);
|
220
|
-
char *destp = RSTRING_PTR(dest);
|
221
|
-
rb_obj_infect(dec, src);
|
222
|
-
rb_obj_infect(dest, dec);
|
223
|
-
size_t s = aux_ZBUFF_decompressContinue(p, destp, &destsize, srcp, &srcsize);
|
224
|
-
extzstd_check_error(s);
|
225
|
-
rb_str_set_len(dest, destsize);
|
226
|
-
if (srcsize == 0) {
|
227
|
-
return Qnil;
|
228
|
-
} else {
|
229
|
-
return SIZET2NUM(srcoff1 + srcsize);
|
230
|
-
}
|
231
|
-
}
|
232
|
-
|
233
|
-
static VALUE
|
234
|
-
bufdec_s_recommended_insize(VALUE mod)
|
235
|
-
{
|
236
|
-
return SIZET2NUM(ZBUFF_recommendedDInSize());
|
237
|
-
}
|
238
|
-
|
239
|
-
static VALUE
|
240
|
-
bufdec_s_recommended_outsize(VALUE mod)
|
241
|
-
{
|
242
|
-
return SIZET2NUM(ZBUFF_recommendedDOutSize());
|
243
|
-
}
|
244
|
-
|
245
|
-
static void
|
246
|
-
init_buffered_decoder(void)
|
247
|
-
{
|
248
|
-
VALUE cBufDecoder = rb_define_class_under(extzstd_mZstd, "BufferedDecoder", rb_cObject);
|
249
|
-
rb_define_alloc_func(cBufDecoder, bufdec_alloc);
|
250
|
-
rb_define_method(cBufDecoder, "initialize", RUBY_METHOD_FUNC(bufdec_init), 1);
|
251
|
-
rb_define_method(cBufDecoder, "continue", RUBY_METHOD_FUNC(bufdec_continue), 4);
|
252
|
-
rb_define_singleton_method(cBufDecoder, "recommended_insize", RUBY_METHOD_FUNC(bufdec_s_recommended_insize), 0);
|
253
|
-
rb_define_singleton_method(cBufDecoder, "recommended_outsize", RUBY_METHOD_FUNC(bufdec_s_recommended_outsize), 0);
|
254
|
-
}
|
255
|
-
|
256
|
-
/*
|
257
|
-
* generic
|
258
|
-
*/
|
259
|
-
|
260
|
-
void
|
261
|
-
extzstd_init_buffered(void)
|
262
|
-
{
|
263
|
-
init_buffered_encoder();
|
264
|
-
init_buffered_decoder();
|
265
|
-
}
|