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
data/ext/depend
ADDED
data/ext/extconf.rb
CHANGED
@@ -2,9 +2,13 @@
|
|
2
2
|
|
3
3
|
require "mkmf"
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
5
|
+
$INCFLAGS = %w(
|
6
|
+
-I$(srcdir)/../contrib
|
7
|
+
-I$(srcdir)/../contrib/zstd/lib
|
8
|
+
-I$(srcdir)/../contrib/zstd/lib/common
|
9
|
+
-I$(srcdir)/../contrib/zstd/lib/dictBuilder
|
10
|
+
-I$(srcdir)/../contrib/zstd/lib/legacy
|
11
|
+
).join(" ") + " #$INCFLAGS"
|
8
12
|
|
9
13
|
#dir = File.dirname(__FILE__).gsub(/[\[\{\?\*]/, "[\\0]")
|
10
14
|
#filepattern = "{.,../contrib/zstd}/**/*.c"
|
@@ -13,8 +17,17 @@ find_header "zstd_legacy.h", "$(srcdir)/../contrib/zstd/legacy" or abort "can't
|
|
13
17
|
#$srcs = files
|
14
18
|
#$VPATH.push "$(srcdir)/../contrib/zstd", "$(srcdir)/../contrib/zstd/legacy"
|
15
19
|
|
16
|
-
if RbConfig::CONFIG["arch"] =~ /mingw/
|
17
|
-
$LDFLAGS << " -static-libgcc"
|
20
|
+
if RbConfig::CONFIG["arch"] =~ /mingw/i
|
21
|
+
$LDFLAGS << " -static-libgcc" if try_ldflags("-static-libgcc")
|
22
|
+
else
|
23
|
+
if try_compile(<<-"VISIBILITY")
|
24
|
+
__attribute__ ((visibility("hidden"))) int conftest(void) { return 0; }
|
25
|
+
VISIBILITY
|
26
|
+
if try_cflags("-fvisibility=hidden")
|
27
|
+
$CFLAGS << " -fvisibility=hidden"
|
28
|
+
$defs << %('-DRBEXT_API=__attribute__ ((visibility("default")))')
|
29
|
+
end
|
30
|
+
end
|
18
31
|
end
|
19
32
|
|
20
33
|
create_makefile File.join(RUBY_VERSION.slice(/\d+\.\d+/), "extzstd")
|
data/ext/extzstd.c
CHANGED
@@ -1,10 +1,13 @@
|
|
1
1
|
#include "extzstd.h"
|
2
|
-
#include <mem.h>
|
3
|
-
#include <
|
2
|
+
#include <zstd/lib/common/mem.h>
|
3
|
+
#include <zstd_errors.h>
|
4
4
|
#include <zdict.h>
|
5
5
|
|
6
6
|
VALUE extzstd_mZstd;
|
7
7
|
|
8
|
+
static ID id_initialize;
|
9
|
+
static ID id_error_code;
|
10
|
+
|
8
11
|
/*
|
9
12
|
* constant Zstd::LIBRARY_VERSION
|
10
13
|
*/
|
@@ -55,25 +58,6 @@ init_libver(void)
|
|
55
58
|
VALUE extzstd_mExceptions;
|
56
59
|
|
57
60
|
VALUE extzstd_eError;
|
58
|
-
VALUE extzstd_eError;
|
59
|
-
VALUE extzstd_eGenericError;
|
60
|
-
VALUE extzstd_ePrefixUnknownError;
|
61
|
-
VALUE extzstd_eFrameParameterUnsupportedError;
|
62
|
-
VALUE extzstd_eFrameParameterUnsupportedBy32bitsError;
|
63
|
-
VALUE extzstd_eCompressionParameterUnsupportedError;
|
64
|
-
VALUE extzstd_eInitMissingError;
|
65
|
-
VALUE extzstd_eMemoryAllocationError;
|
66
|
-
VALUE extzstd_eStageWrongError;
|
67
|
-
VALUE extzstd_eDstSizeTooSmallError;
|
68
|
-
VALUE extzstd_eSrcSizeWrongError;
|
69
|
-
VALUE extzstd_eCorruptionDetectedError;
|
70
|
-
VALUE extzstd_eChecksumWrongError;
|
71
|
-
VALUE extzstd_eTableLogTooLargeError;
|
72
|
-
VALUE extzstd_eMaxSymbolValueTooLargeError;
|
73
|
-
VALUE extzstd_eMaxSymbolValueTooSmallError;
|
74
|
-
VALUE extzstd_eDictionaryCorruptedError;
|
75
|
-
VALUE extzstd_eDictionaryWrongError;
|
76
|
-
|
77
61
|
|
78
62
|
void
|
79
63
|
extzstd_check_error(ssize_t errcode)
|
@@ -90,16 +74,20 @@ extzstd_error(ssize_t errcode)
|
|
90
74
|
}
|
91
75
|
|
92
76
|
VALUE
|
93
|
-
extzstd_make_errorf(
|
77
|
+
extzstd_make_errorf(ssize_t errcode, const char *fmt, ...)
|
94
78
|
{
|
79
|
+
VALUE e;
|
80
|
+
|
95
81
|
if (fmt && strlen(fmt) > 0) {
|
82
|
+
VALUE args[] = { SSIZET2NUM(errcode), Qnil };
|
96
83
|
va_list va;
|
97
84
|
va_start(va, fmt);
|
98
|
-
|
85
|
+
args[1] = rb_vsprintf(fmt, va);
|
99
86
|
va_end(va);
|
100
|
-
return
|
87
|
+
return rb_class_new_instance(2, args, extzstd_eError);
|
101
88
|
} else {
|
102
|
-
|
89
|
+
VALUE args[] = { SSIZET2NUM(errcode) };
|
90
|
+
return rb_class_new_instance(1, args, extzstd_eError);
|
103
91
|
}
|
104
92
|
}
|
105
93
|
|
@@ -108,33 +96,34 @@ extzstd_make_error(ssize_t errcode)
|
|
108
96
|
{
|
109
97
|
if (!ZSTD_isError(errcode)) { return Qnil; }
|
110
98
|
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
CASE_ERROR(ZSTD_error_dictionary_wrong, extzstd_eDictionaryWrongError, NULL);
|
132
|
-
default:
|
133
|
-
return extzstd_make_errorf(extzstd_eError,
|
134
|
-
"unknown zstd error code (%d)", errcode);
|
135
|
-
}
|
99
|
+
return extzstd_make_errorf(ZSTD_getErrorCode(errcode), NULL);
|
100
|
+
}
|
101
|
+
|
102
|
+
static VALUE
|
103
|
+
err_initialize(int argc, VALUE argv[], VALUE err)
|
104
|
+
{
|
105
|
+
VALUE errcode;
|
106
|
+
|
107
|
+
rb_scan_args(argc, argv, "1*", &errcode, NULL);
|
108
|
+
rb_call_super(argc - 1, argv + 1);
|
109
|
+
rb_ivar_set(err, id_error_code, errcode);
|
110
|
+
|
111
|
+
return err;
|
112
|
+
}
|
113
|
+
|
114
|
+
static VALUE
|
115
|
+
err_errcode(VALUE err)
|
116
|
+
{
|
117
|
+
return rb_ivar_get(err, id_error_code);
|
118
|
+
}
|
136
119
|
|
137
|
-
|
120
|
+
static VALUE
|
121
|
+
err_to_s(VALUE err)
|
122
|
+
{
|
123
|
+
ZSTD_ErrorCode code = (ZSTD_ErrorCode)NUM2SSIZET(rb_ivar_get(err, id_error_code));
|
124
|
+
VALUE mesg = rb_call_super(0, NULL);
|
125
|
+
VALUE mesg2 = rb_sprintf(" - %s (errcode: %d)", ZSTD_getErrorString(code), (int)code);
|
126
|
+
return rb_str_plus(mesg, mesg2);
|
138
127
|
}
|
139
128
|
|
140
129
|
static void
|
@@ -144,57 +133,10 @@ init_error(void)
|
|
144
133
|
|
145
134
|
extzstd_eError = rb_define_class_under(extzstd_mZstd, "Error", rb_eRuntimeError);
|
146
135
|
rb_include_module(extzstd_eError, extzstd_mExceptions);
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
extzstd_ePrefixUnknownError = rb_define_class_under(extzstd_mZstd, "PrefixUnknownError", rb_eArgError);
|
152
|
-
rb_include_module(extzstd_ePrefixUnknownError, extzstd_mExceptions);
|
153
|
-
|
154
|
-
extzstd_eFrameParameterUnsupportedError = rb_define_class_under(extzstd_mZstd, "FrameParameterUnsupportedError", rb_eRuntimeError);
|
155
|
-
rb_include_module(extzstd_eFrameParameterUnsupportedError, extzstd_mExceptions);
|
156
|
-
|
157
|
-
extzstd_eFrameParameterUnsupportedBy32bitsError = rb_define_class_under(extzstd_mZstd, "FrameParameterUnsupportedBy32bitsImplementationError", rb_eRuntimeError);
|
158
|
-
rb_include_module(extzstd_eFrameParameterUnsupportedBy32bitsError, extzstd_mExceptions);
|
159
|
-
|
160
|
-
extzstd_eCompressionParameterUnsupportedError = rb_define_class_under(extzstd_mZstd, "CompressionParameterUnsupportedError", rb_eRuntimeError);
|
161
|
-
rb_include_module(extzstd_eCompressionParameterUnsupportedError, extzstd_mExceptions);
|
162
|
-
|
163
|
-
extzstd_eInitMissingError = rb_define_class_under(extzstd_mZstd, "InitMissingError", rb_eRuntimeError);
|
164
|
-
rb_include_module(extzstd_eInitMissingError, extzstd_mExceptions);
|
165
|
-
|
166
|
-
extzstd_eMemoryAllocationError = rb_define_class_under(extzstd_mZstd, "MemoryAllocationError", aux_const_dig_str(rb_cObject, "Errno", "ENOMEM"));
|
167
|
-
rb_include_module(extzstd_eMemoryAllocationError, extzstd_mExceptions);
|
168
|
-
|
169
|
-
extzstd_eStageWrongError = rb_define_class_under(extzstd_mZstd, "StageWrongError", rb_eRuntimeError);
|
170
|
-
rb_include_module(extzstd_eStageWrongError, extzstd_mExceptions);
|
171
|
-
|
172
|
-
extzstd_eDstSizeTooSmallError = rb_define_class_under(extzstd_mZstd, "DstSizeTooSmallError", rb_eArgError);
|
173
|
-
rb_include_module(extzstd_eDstSizeTooSmallError, extzstd_mExceptions);
|
174
|
-
|
175
|
-
extzstd_eSrcSizeWrongError = rb_define_class_under(extzstd_mZstd, "SrcSizeWrongError", rb_eArgError);
|
176
|
-
rb_include_module(extzstd_eSrcSizeWrongError, extzstd_mExceptions);
|
177
|
-
|
178
|
-
extzstd_eCorruptionDetectedError = rb_define_class_under(extzstd_mZstd, "CorruptionDetectedError", rb_eRuntimeError);
|
179
|
-
rb_include_module(extzstd_eCorruptionDetectedError, extzstd_mExceptions);
|
180
|
-
|
181
|
-
extzstd_eChecksumWrongError = rb_define_class_under(extzstd_mZstd, "ChecksumWrongError", rb_eRuntimeError);
|
182
|
-
rb_include_module(extzstd_eChecksumWrongError, extzstd_mExceptions);
|
183
|
-
|
184
|
-
extzstd_eTableLogTooLargeError = rb_define_class_under(extzstd_mZstd, "TableLogTooLargeError", rb_eArgError);
|
185
|
-
rb_include_module(extzstd_eTableLogTooLargeError, extzstd_mExceptions);
|
186
|
-
|
187
|
-
extzstd_eMaxSymbolValueTooLargeError = rb_define_class_under(extzstd_mZstd, "MaxSymbolValueTooLargeError", rb_eArgError);
|
188
|
-
rb_include_module(extzstd_eMaxSymbolValueTooLargeError, extzstd_mExceptions);
|
189
|
-
|
190
|
-
extzstd_eMaxSymbolValueTooSmallError = rb_define_class_under(extzstd_mZstd, "MaxSymbolValueTooSmallError", rb_eArgError);
|
191
|
-
rb_include_module(extzstd_eMaxSymbolValueTooSmallError, extzstd_mExceptions);
|
192
|
-
|
193
|
-
extzstd_eDictionaryCorruptedError = rb_define_class_under(extzstd_mZstd, "DictionaryCorruptedError", rb_eRuntimeError);
|
194
|
-
rb_include_module(extzstd_eDictionaryCorruptedError, extzstd_mExceptions);
|
195
|
-
|
196
|
-
extzstd_eDictionaryWrongError = rb_define_class_under(extzstd_mZstd, "DictionaryWrongError", rb_eRuntimeError);
|
197
|
-
rb_include_module(extzstd_eDictionaryWrongError, extzstd_mExceptions);
|
136
|
+
rb_define_method(extzstd_eError, "initialize", err_initialize, -1);
|
137
|
+
rb_define_method(extzstd_eError, "error_code", err_errcode, 0);
|
138
|
+
rb_define_method(extzstd_eError, "to_s", err_to_s, 0);
|
139
|
+
rb_define_alias(extzstd_eError, "errcode", "error_code");
|
198
140
|
}
|
199
141
|
|
200
142
|
/*
|
@@ -207,22 +149,31 @@ init_constants(void)
|
|
207
149
|
VALUE mConstants = rb_define_module_under(extzstd_mZstd, "Constants");
|
208
150
|
rb_include_module(extzstd_mZstd, mConstants);
|
209
151
|
|
152
|
+
rb_define_const(mConstants, "ZSTD_MAX_COMPRESSION_LEVEL", INT2NUM(ZSTD_maxCLevel()));
|
153
|
+
rb_define_const(mConstants, "MAX_COMPRESSION_LEVEL", INT2NUM(ZSTD_maxCLevel()));
|
154
|
+
|
210
155
|
rb_define_const(mConstants, "ZSTD_FAST", INT2NUM(ZSTD_fast));
|
211
156
|
rb_define_const(mConstants, "ZSTD_DFAST", INT2NUM(ZSTD_dfast));
|
212
157
|
rb_define_const(mConstants, "ZSTD_GREEDY", INT2NUM(ZSTD_greedy));
|
213
158
|
rb_define_const(mConstants, "ZSTD_LAZY", INT2NUM(ZSTD_lazy));
|
214
159
|
rb_define_const(mConstants, "ZSTD_LAZY2", INT2NUM(ZSTD_lazy2));
|
215
160
|
rb_define_const(mConstants, "ZSTD_BTLAZY2", INT2NUM(ZSTD_btlazy2));
|
161
|
+
rb_define_const(mConstants, "ZSTD_BTOPT", INT2NUM(ZSTD_btopt));
|
162
|
+
rb_define_const(mConstants, "ZSTD_BTULTRA", INT2NUM(ZSTD_btultra));
|
163
|
+
rb_define_const(mConstants, "ZSTD_BTULTRA2", INT2NUM(ZSTD_btultra2));
|
216
164
|
rb_define_const(mConstants, "ZSTD_WINDOWLOG_MAX", INT2NUM(ZSTD_WINDOWLOG_MAX));
|
217
165
|
rb_define_const(mConstants, "ZSTD_WINDOWLOG_MIN", INT2NUM(ZSTD_WINDOWLOG_MIN));
|
218
|
-
rb_define_const(mConstants, "ZSTD_CHAINLOG_MAX", INT2NUM(ZSTD_CHAINLOG_MAX));
|
219
|
-
rb_define_const(mConstants, "ZSTD_CHAINLOG_MIN", INT2NUM(ZSTD_CHAINLOG_MIN));
|
220
166
|
rb_define_const(mConstants, "ZSTD_HASHLOG_MAX", INT2NUM(ZSTD_HASHLOG_MAX));
|
221
167
|
rb_define_const(mConstants, "ZSTD_HASHLOG_MIN", INT2NUM(ZSTD_HASHLOG_MIN));
|
168
|
+
rb_define_const(mConstants, "ZSTD_CHAINLOG_MAX", INT2NUM(ZSTD_CHAINLOG_MAX));
|
169
|
+
rb_define_const(mConstants, "ZSTD_CHAINLOG_MIN", INT2NUM(ZSTD_CHAINLOG_MIN));
|
170
|
+
rb_define_const(mConstants, "ZSTD_HASHLOG3_MAX", INT2NUM(ZSTD_HASHLOG3_MAX));
|
222
171
|
rb_define_const(mConstants, "ZSTD_SEARCHLOG_MAX", INT2NUM(ZSTD_SEARCHLOG_MAX));
|
223
172
|
rb_define_const(mConstants, "ZSTD_SEARCHLOG_MIN", INT2NUM(ZSTD_SEARCHLOG_MIN));
|
224
|
-
rb_define_const(mConstants, "ZSTD_SEARCHLENGTH_MAX", INT2NUM(ZSTD_SEARCHLENGTH_MAX));
|
225
|
-
rb_define_const(mConstants, "ZSTD_SEARCHLENGTH_MIN", INT2NUM(ZSTD_SEARCHLENGTH_MIN));
|
173
|
+
//rb_define_const(mConstants, "ZSTD_SEARCHLENGTH_MAX", INT2NUM(ZSTD_SEARCHLENGTH_MAX));
|
174
|
+
//rb_define_const(mConstants, "ZSTD_SEARCHLENGTH_MIN", INT2NUM(ZSTD_SEARCHLENGTH_MIN));
|
175
|
+
//rb_define_const(mConstants, "ZSTD_TARGETLENGTH_MAX", INT2NUM(ZSTD_TARGETLENGTH_MAX));
|
176
|
+
//rb_define_const(mConstants, "ZSTD_TARGETLENGTH_MIN", INT2NUM(ZSTD_TARGETLENGTH_MIN));
|
226
177
|
|
227
178
|
rb_define_const(mConstants, "FAST", INT2NUM(ZSTD_fast));
|
228
179
|
rb_define_const(mConstants, "DFAST", INT2NUM(ZSTD_dfast));
|
@@ -230,16 +181,22 @@ init_constants(void)
|
|
230
181
|
rb_define_const(mConstants, "LAZY", INT2NUM(ZSTD_lazy));
|
231
182
|
rb_define_const(mConstants, "LAZY2", INT2NUM(ZSTD_lazy2));
|
232
183
|
rb_define_const(mConstants, "BTLAZY2", INT2NUM(ZSTD_btlazy2));
|
184
|
+
rb_define_const(mConstants, "BTOPT", INT2NUM(ZSTD_btopt));
|
185
|
+
rb_define_const(mConstants, "BTULTRA", INT2NUM(ZSTD_btultra));
|
186
|
+
rb_define_const(mConstants, "BTULTRA2", INT2NUM(ZSTD_btultra2));
|
233
187
|
rb_define_const(mConstants, "WINDOWLOG_MAX", INT2NUM(ZSTD_WINDOWLOG_MAX));
|
234
188
|
rb_define_const(mConstants, "WINDOWLOG_MIN", INT2NUM(ZSTD_WINDOWLOG_MIN));
|
235
|
-
rb_define_const(mConstants, "CHAINLOG_MAX", INT2NUM(ZSTD_CHAINLOG_MAX));
|
236
|
-
rb_define_const(mConstants, "CHAINLOG_MIN", INT2NUM(ZSTD_CHAINLOG_MIN));
|
237
189
|
rb_define_const(mConstants, "HASHLOG_MAX", INT2NUM(ZSTD_HASHLOG_MAX));
|
238
190
|
rb_define_const(mConstants, "HASHLOG_MIN", INT2NUM(ZSTD_HASHLOG_MIN));
|
191
|
+
rb_define_const(mConstants, "CHAINLOG_MAX", INT2NUM(ZSTD_CHAINLOG_MAX));
|
192
|
+
rb_define_const(mConstants, "CHAINLOG_MIN", INT2NUM(ZSTD_CHAINLOG_MIN));
|
193
|
+
rb_define_const(mConstants, "HASHLOG3_MAX", INT2NUM(ZSTD_HASHLOG3_MAX));
|
239
194
|
rb_define_const(mConstants, "SEARCHLOG_MAX", INT2NUM(ZSTD_SEARCHLOG_MAX));
|
240
195
|
rb_define_const(mConstants, "SEARCHLOG_MIN", INT2NUM(ZSTD_SEARCHLOG_MIN));
|
241
|
-
rb_define_const(mConstants, "SEARCHLENGTH_MAX", INT2NUM(ZSTD_SEARCHLENGTH_MAX));
|
242
|
-
rb_define_const(mConstants, "SEARCHLENGTH_MIN", INT2NUM(ZSTD_SEARCHLENGTH_MIN));
|
196
|
+
//rb_define_const(mConstants, "SEARCHLENGTH_MAX", INT2NUM(ZSTD_SEARCHLENGTH_MAX));
|
197
|
+
//rb_define_const(mConstants, "SEARCHLENGTH_MIN", INT2NUM(ZSTD_SEARCHLENGTH_MIN));
|
198
|
+
//rb_define_const(mConstants, "TARGETLENGTH_MAX", INT2NUM(ZSTD_TARGETLENGTH_MAX));
|
199
|
+
//rb_define_const(mConstants, "TARGETLENGTH_MIN", INT2NUM(ZSTD_TARGETLENGTH_MIN));
|
243
200
|
}
|
244
201
|
|
245
202
|
/*
|
@@ -249,33 +206,33 @@ init_constants(void)
|
|
249
206
|
VALUE extzstd_cParams;
|
250
207
|
|
251
208
|
AUX_IMPLEMENT_CONTEXT(
|
252
|
-
ZSTD_parameters,
|
253
|
-
|
254
|
-
|
209
|
+
ZSTD_parameters, params_type, "extzstd.Parameters",
|
210
|
+
params_alloc_dummy, NULL, free, NULL,
|
211
|
+
getparamsp, getparams, params_p);
|
255
212
|
|
256
213
|
ZSTD_parameters *
|
257
|
-
|
214
|
+
extzstd_getparams(VALUE v)
|
258
215
|
{
|
259
|
-
return
|
216
|
+
return getparams(v);
|
260
217
|
}
|
261
218
|
|
262
219
|
int
|
263
|
-
|
220
|
+
extzstd_params_p(VALUE v)
|
264
221
|
{
|
265
|
-
return
|
222
|
+
return params_p(v);
|
266
223
|
}
|
267
224
|
|
268
225
|
static VALUE
|
269
|
-
|
226
|
+
params_alloc(VALUE mod)
|
270
227
|
{
|
271
228
|
ZSTD_parameters *p;
|
272
|
-
return TypedData_Make_Struct(mod, ZSTD_parameters, &
|
229
|
+
return TypedData_Make_Struct(mod, ZSTD_parameters, ¶ms_type, p);
|
273
230
|
}
|
274
231
|
|
275
232
|
VALUE
|
276
233
|
extzstd_params_alloc(ZSTD_parameters **p)
|
277
234
|
{
|
278
|
-
return TypedData_Make_Struct(extzstd_cParams, ZSTD_parameters, &
|
235
|
+
return TypedData_Make_Struct(extzstd_cParams, ZSTD_parameters, ¶ms_type, *p);
|
279
236
|
}
|
280
237
|
|
281
238
|
/*
|
@@ -290,43 +247,23 @@ extzstd_params_alloc(ZSTD_parameters **p)
|
|
290
247
|
* [opts contentlog: nil]
|
291
248
|
* [opts hashlog: nil]
|
292
249
|
* [opts searchlog: nil]
|
293
|
-
* [opts
|
250
|
+
* [opts minmatch: nil]
|
251
|
+
* [opts targetlength: nil]
|
294
252
|
* [opts strategy: nil]
|
295
253
|
*/
|
296
254
|
static VALUE
|
297
|
-
|
255
|
+
params_init(int argc, VALUE argv[], VALUE v)
|
298
256
|
{
|
299
|
-
ZSTD_parameters *p =
|
257
|
+
ZSTD_parameters *p = getparams(v);
|
300
258
|
uint64_t sizehint;
|
301
259
|
size_t dictsize;
|
302
260
|
int level;
|
303
261
|
VALUE opts = Qnil;
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
}
|
310
|
-
}
|
311
|
-
if (argc == 0) {
|
312
|
-
level = 0;
|
313
|
-
sizehint = 0;
|
314
|
-
dictsize = 0;
|
315
|
-
} else if (argc == 1) {
|
316
|
-
level = aux_num2int(argv[0], 0);
|
317
|
-
sizehint = 0;
|
318
|
-
dictsize = 0;
|
319
|
-
} else if (argc == 2) {
|
320
|
-
level = aux_num2int(argv[0], 0);
|
321
|
-
sizehint = aux_num2int_u64(argv[1], 0);
|
322
|
-
dictsize = 0;
|
323
|
-
} else if (argc == 3) {
|
324
|
-
level = aux_num2int(argv[0], 0);
|
325
|
-
sizehint = aux_num2int_u64(argv[1], 0);
|
326
|
-
dictsize = aux_num2int_u64(argv[2], 0);
|
327
|
-
} else {
|
328
|
-
rb_raise(rb_eArgError, "wrong number of argument (%d for 0..3 with keywords)", argc0);
|
329
|
-
}
|
262
|
+
|
263
|
+
argc = rb_scan_args(argc, argv, "03:", NULL, NULL, NULL, &opts);
|
264
|
+
level = argc > 0 ? aux_num2int(argv[0], 0) : 0;
|
265
|
+
sizehint = argc > 1 ? aux_num2int_u64(argv[1], 0) : 0;
|
266
|
+
dictsize = argc > 2 ? aux_num2int_u64(argv[2], 0) : 0;
|
330
267
|
|
331
268
|
*p = ZSTD_getParams(level, sizehint, dictsize);
|
332
269
|
|
@@ -343,8 +280,12 @@ encparams_init(int argc, VALUE argv[], VALUE v)
|
|
343
280
|
SETUP_PARAM(p->cParams.chainLog, opts, "chainlog", NUM2UINT);
|
344
281
|
SETUP_PARAM(p->cParams.hashLog, opts, "hashlog", NUM2UINT);
|
345
282
|
SETUP_PARAM(p->cParams.searchLog, opts, "searchlog", NUM2UINT);
|
346
|
-
SETUP_PARAM(p->cParams.
|
283
|
+
SETUP_PARAM(p->cParams.minMatch, opts, "minmatch", NUM2UINT);
|
284
|
+
SETUP_PARAM(p->cParams.targetLength, opts, "targetlength", NUM2UINT);
|
347
285
|
SETUP_PARAM(p->cParams.strategy, opts, "strategy", NUM2UINT);
|
286
|
+
SETUP_PARAM(p->fParams.contentSizeFlag, opts, "contentsize", RTEST);
|
287
|
+
SETUP_PARAM(p->fParams.checksumFlag, opts, "checksum", RTEST);
|
288
|
+
SETUP_PARAM(p->fParams.noDictIDFlag, opts, "nodictid", RTEST);
|
348
289
|
#undef SETUP_PARAM
|
349
290
|
}
|
350
291
|
|
@@ -352,10 +293,10 @@ encparams_init(int argc, VALUE argv[], VALUE v)
|
|
352
293
|
}
|
353
294
|
|
354
295
|
static VALUE
|
355
|
-
|
296
|
+
params_init_copy(VALUE params, VALUE src)
|
356
297
|
{
|
357
|
-
ZSTD_parameters *a =
|
358
|
-
ZSTD_parameters *b =
|
298
|
+
ZSTD_parameters *a = getparams(params);
|
299
|
+
ZSTD_parameters *b = getparams(src);
|
359
300
|
rb_check_frozen(params);
|
360
301
|
rb_obj_infect(params, src);
|
361
302
|
memcpy(a, b, sizeof(*a));
|
@@ -363,9 +304,9 @@ encparams_init_copy(VALUE params, VALUE src)
|
|
363
304
|
}
|
364
305
|
|
365
306
|
//static VALUE
|
366
|
-
//
|
307
|
+
//params_validate(VALUE v)
|
367
308
|
//{
|
368
|
-
// ZSTD_validateParams(
|
309
|
+
// ZSTD_validateParams(getparams(v));
|
369
310
|
// return v;
|
370
311
|
//}
|
371
312
|
|
@@ -373,28 +314,29 @@ encparams_init_copy(VALUE params, VALUE src)
|
|
373
314
|
static VALUE \
|
374
315
|
GETTER(VALUE v) \
|
375
316
|
{ \
|
376
|
-
return UINT2NUM(
|
317
|
+
return UINT2NUM(getparams(v)->cParams.FIELD); \
|
377
318
|
} \
|
378
319
|
\
|
379
320
|
static VALUE \
|
380
321
|
SETTER(VALUE v, VALUE n) \
|
381
322
|
{ \
|
382
|
-
|
323
|
+
getparams(v)->cParams.FIELD = NUM2UINT(n); \
|
383
324
|
return n; \
|
384
325
|
} \
|
385
326
|
|
386
|
-
//IMP_PARAMS(
|
387
|
-
IMP_PARAMS(
|
388
|
-
IMP_PARAMS(
|
389
|
-
IMP_PARAMS(
|
390
|
-
IMP_PARAMS(
|
391
|
-
IMP_PARAMS(
|
392
|
-
IMP_PARAMS(
|
327
|
+
//IMP_PARAMS(params_srcsize, params_set_srcsize, srcSize);
|
328
|
+
IMP_PARAMS(params_windowlog, params_set_windowlog, windowLog);
|
329
|
+
IMP_PARAMS(params_chainlog, params_set_chainlog, chainLog);
|
330
|
+
IMP_PARAMS(params_hashlog, params_set_hashlog, hashLog);
|
331
|
+
IMP_PARAMS(params_searchlog, params_set_searchlog, searchLog);
|
332
|
+
IMP_PARAMS(params_minmatch, params_set_minmatch, minMatch);
|
333
|
+
IMP_PARAMS(params_targetlength, params_set_targetlength, targetLength);
|
334
|
+
IMP_PARAMS(params_strategy, params_set_strategy, strategy);
|
393
335
|
|
394
336
|
#undef IMP_PARAMS
|
395
337
|
|
396
338
|
static VALUE
|
397
|
-
|
339
|
+
params_s_get_preset(int argc, VALUE argv[], VALUE mod)
|
398
340
|
{
|
399
341
|
int level;
|
400
342
|
uint64_t sizehint;
|
@@ -426,72 +368,79 @@ encparams_s_get_preset(int argc, VALUE argv[], VALUE mod)
|
|
426
368
|
}
|
427
369
|
|
428
370
|
ZSTD_parameters *p;
|
429
|
-
VALUE v = TypedData_Make_Struct(mod, ZSTD_parameters, &
|
371
|
+
VALUE v = TypedData_Make_Struct(mod, ZSTD_parameters, ¶ms_type, p);
|
430
372
|
*p = ZSTD_getParams(level, sizehint, dictsize);
|
431
373
|
return v;
|
432
374
|
}
|
433
375
|
|
434
376
|
/*
|
435
|
-
* Document-method: Zstd::
|
436
|
-
* Document-method: Zstd::
|
437
|
-
* Document-method: Zstd::
|
438
|
-
* Document-method: Zstd::
|
439
|
-
* Document-method: Zstd::
|
440
|
-
* Document-method: Zstd::
|
441
|
-
* Document-method: Zstd::
|
442
|
-
* Document-method: Zstd::
|
443
|
-
* Document-method: Zstd::
|
444
|
-
* Document-method: Zstd::
|
445
|
-
* Document-method: Zstd::
|
446
|
-
* Document-method: Zstd::
|
377
|
+
* Document-method: Zstd::Parameters#windowlog
|
378
|
+
* Document-method: Zstd::Parameters#windowlog=
|
379
|
+
* Document-method: Zstd::Parameters#chainlog
|
380
|
+
* Document-method: Zstd::Parameters#chainlog=
|
381
|
+
* Document-method: Zstd::Parameters#hashlog
|
382
|
+
* Document-method: Zstd::Parameters#hashlog=
|
383
|
+
* Document-method: Zstd::Parameters#searchlog
|
384
|
+
* Document-method: Zstd::Parameters#searchlog=
|
385
|
+
* Document-method: Zstd::Parameters#minmatch
|
386
|
+
* Document-method: Zstd::Parameters#minmatch=
|
387
|
+
* Document-method: Zstd::Parameters#targetlength
|
388
|
+
* Document-method: Zstd::Parameters#targetlength=
|
389
|
+
* Document-method: Zstd::Parameters#strategy
|
390
|
+
* Document-method: Zstd::Parameters#strategy=
|
447
391
|
*
|
448
392
|
* Get/Set any field from/to struct ZSTD_parameters of C layer.
|
449
393
|
*/
|
450
394
|
|
451
395
|
static void
|
452
|
-
|
396
|
+
init_params(void)
|
453
397
|
{
|
454
|
-
extzstd_cParams = rb_define_class_under(extzstd_mZstd, "
|
455
|
-
rb_define_alloc_func(extzstd_cParams,
|
456
|
-
rb_define_method(extzstd_cParams, "initialize", RUBY_METHOD_FUNC(
|
457
|
-
rb_define_method(extzstd_cParams, "initialize_copy", RUBY_METHOD_FUNC(
|
458
|
-
//rb_define_method(extzstd_cParams, "validate", RUBY_METHOD_FUNC(
|
459
|
-
//rb_define_method(extzstd_cParams, "srcsize", RUBY_METHOD_FUNC(
|
460
|
-
//rb_define_method(extzstd_cParams, "srcsize=", RUBY_METHOD_FUNC(
|
461
|
-
rb_define_method(extzstd_cParams, "windowlog", RUBY_METHOD_FUNC(
|
462
|
-
rb_define_method(extzstd_cParams, "windowlog=", RUBY_METHOD_FUNC(
|
463
|
-
rb_define_method(extzstd_cParams, "chainlog", RUBY_METHOD_FUNC(
|
464
|
-
rb_define_method(extzstd_cParams, "chainlog=", RUBY_METHOD_FUNC(
|
465
|
-
rb_define_method(extzstd_cParams, "hashlog", RUBY_METHOD_FUNC(
|
466
|
-
rb_define_method(extzstd_cParams, "hashlog=", RUBY_METHOD_FUNC(
|
467
|
-
rb_define_method(extzstd_cParams, "searchlog", RUBY_METHOD_FUNC(
|
468
|
-
rb_define_method(extzstd_cParams, "searchlog=", RUBY_METHOD_FUNC(
|
469
|
-
rb_define_method(extzstd_cParams, "
|
470
|
-
rb_define_method(extzstd_cParams, "
|
471
|
-
rb_define_method(extzstd_cParams, "
|
472
|
-
rb_define_method(extzstd_cParams, "
|
473
|
-
|
474
|
-
|
398
|
+
extzstd_cParams = rb_define_class_under(extzstd_mZstd, "Parameters", rb_cObject);
|
399
|
+
rb_define_alloc_func(extzstd_cParams, params_alloc);
|
400
|
+
rb_define_method(extzstd_cParams, "initialize", RUBY_METHOD_FUNC(params_init), -1);
|
401
|
+
rb_define_method(extzstd_cParams, "initialize_copy", RUBY_METHOD_FUNC(params_init_copy), 1);
|
402
|
+
//rb_define_method(extzstd_cParams, "validate", RUBY_METHOD_FUNC(params_validate), 0);
|
403
|
+
//rb_define_method(extzstd_cParams, "srcsize", RUBY_METHOD_FUNC(params_srcsize), 0);
|
404
|
+
//rb_define_method(extzstd_cParams, "srcsize=", RUBY_METHOD_FUNC(params_set_srcsize), 1);
|
405
|
+
rb_define_method(extzstd_cParams, "windowlog", RUBY_METHOD_FUNC(params_windowlog), 0);
|
406
|
+
rb_define_method(extzstd_cParams, "windowlog=", RUBY_METHOD_FUNC(params_set_windowlog), 1);
|
407
|
+
rb_define_method(extzstd_cParams, "chainlog", RUBY_METHOD_FUNC(params_chainlog), 0);
|
408
|
+
rb_define_method(extzstd_cParams, "chainlog=", RUBY_METHOD_FUNC(params_set_chainlog), 1);
|
409
|
+
rb_define_method(extzstd_cParams, "hashlog", RUBY_METHOD_FUNC(params_hashlog), 0);
|
410
|
+
rb_define_method(extzstd_cParams, "hashlog=", RUBY_METHOD_FUNC(params_set_hashlog), 1);
|
411
|
+
rb_define_method(extzstd_cParams, "searchlog", RUBY_METHOD_FUNC(params_searchlog), 0);
|
412
|
+
rb_define_method(extzstd_cParams, "searchlog=", RUBY_METHOD_FUNC(params_set_searchlog), 1);
|
413
|
+
rb_define_method(extzstd_cParams, "minmatch", RUBY_METHOD_FUNC(params_minmatch), 0);
|
414
|
+
rb_define_method(extzstd_cParams, "minmatch=", RUBY_METHOD_FUNC(params_set_minmatch), 1);
|
415
|
+
rb_define_method(extzstd_cParams, "targetlength", RUBY_METHOD_FUNC(params_targetlength), 0);
|
416
|
+
rb_define_method(extzstd_cParams, "targetlength=", RUBY_METHOD_FUNC(params_set_targetlength), 1);
|
417
|
+
rb_define_method(extzstd_cParams, "strategy", RUBY_METHOD_FUNC(params_strategy), 0);
|
418
|
+
rb_define_method(extzstd_cParams, "strategy=", RUBY_METHOD_FUNC(params_set_strategy), 1);
|
419
|
+
|
420
|
+
rb_define_singleton_method(extzstd_cParams, "preset", RUBY_METHOD_FUNC(params_s_get_preset), -1);
|
475
421
|
rb_define_alias(rb_singleton_class(extzstd_cParams), "[]", "preset");
|
476
422
|
}
|
477
423
|
|
478
424
|
|
479
425
|
/*
|
480
|
-
*
|
426
|
+
* module Zstd::Dictionary
|
481
427
|
*/
|
482
428
|
|
429
|
+
static VALUE mDictionary;
|
430
|
+
|
483
431
|
/*
|
484
432
|
* call-seq:
|
485
|
-
*
|
433
|
+
* train_from_buffer(src, dict_capacity) -> dictionary'd string
|
486
434
|
*/
|
487
435
|
static VALUE
|
488
|
-
|
436
|
+
dict_s_train_from_buffer(VALUE mod, VALUE src, VALUE dict_capacity)
|
489
437
|
{
|
490
438
|
rb_check_type(src, RUBY_T_STRING);
|
491
439
|
size_t capa = NUM2SIZET(dict_capacity);
|
492
440
|
VALUE dict = rb_str_buf_new(capa);
|
493
441
|
size_t srcsize = RSTRING_LEN(src);
|
494
|
-
|
442
|
+
const ZDICT_legacy_params_t params = { 0 };
|
443
|
+
size_t s = ZDICT_trainFromBuffer_legacy(RSTRING_PTR(dict), capa, RSTRING_PTR(src), &srcsize, 1, params);
|
495
444
|
extzstd_check_error(s);
|
496
445
|
rb_str_set_len(dict, s);
|
497
446
|
return dict;
|
@@ -499,14 +448,15 @@ ext_s_dict_train_from_buffer(VALUE mod, VALUE src, VALUE dict_capacity)
|
|
499
448
|
|
500
449
|
/*
|
501
450
|
* call-seq:
|
502
|
-
*
|
451
|
+
* add_entropy_tables_from_buffer(dict, dict_capacity, sample) -> dict
|
503
452
|
*/
|
504
453
|
static VALUE
|
505
|
-
|
454
|
+
dict_s_add_entropy_tables_from_buffer(VALUE mod, VALUE dict, VALUE dict_capacity, VALUE sample)
|
506
455
|
{
|
507
456
|
/*
|
508
|
-
* size_t ZDICT_addEntropyTablesFromBuffer(
|
509
|
-
*
|
457
|
+
* size_t ZDICT_addEntropyTablesFromBuffer(
|
458
|
+
* void* dictBuffer, size_t dictContentSize, size_t dictBufferCapacity,
|
459
|
+
* const void* samplesBuffer, const size_t* samplesSizes, unsigned nbSamples);
|
510
460
|
*/
|
511
461
|
|
512
462
|
rb_check_type(dict, RUBY_T_STRING);
|
@@ -514,33 +464,165 @@ ext_s_dict_add_entropy_tables_from_buffer(VALUE mod, VALUE dict, VALUE dict_capa
|
|
514
464
|
size_t capa = NUM2SIZET(dict_capacity);
|
515
465
|
aux_str_modify_expand(dict, capa);
|
516
466
|
size_t samplesize = RSTRING_LEN(sample);
|
517
|
-
size_t s = ZDICT_addEntropyTablesFromBuffer(RSTRING_PTR(dict), RSTRING_LEN(dict), capa, RSTRING_PTR(
|
467
|
+
size_t s = ZDICT_addEntropyTablesFromBuffer(RSTRING_PTR(dict), RSTRING_LEN(dict), capa, RSTRING_PTR(sample), &samplesize, 1);
|
518
468
|
extzstd_check_error(s);
|
519
469
|
rb_str_set_len(dict, s);
|
520
470
|
return dict;
|
521
471
|
}
|
522
472
|
|
473
|
+
static VALUE
|
474
|
+
dict_s_getid(VALUE mod, VALUE dict)
|
475
|
+
{
|
476
|
+
/*
|
477
|
+
* ZDICTLIB_API unsigned ZDICT_getDictID(const void* dictBuffer, size_t dictSize);
|
478
|
+
*/
|
479
|
+
|
480
|
+
rb_check_type(dict, RUBY_T_STRING);
|
481
|
+
const char *p;
|
482
|
+
size_t psize;
|
483
|
+
RSTRING_GETMEM(dict, p, psize);
|
484
|
+
|
485
|
+
size_t s = ZDICT_getDictID(p, psize);
|
486
|
+
extzstd_check_error(s);
|
487
|
+
|
488
|
+
return SIZET2NUM(s);
|
489
|
+
}
|
490
|
+
|
523
491
|
static void
|
524
492
|
init_dictionary(void)
|
525
493
|
{
|
526
|
-
|
527
|
-
rb_define_singleton_method(
|
494
|
+
mDictionary = rb_define_module_under(extzstd_mZstd, "Dictionary");
|
495
|
+
rb_define_singleton_method(mDictionary, "train_from_buffer", dict_s_train_from_buffer, 2);
|
496
|
+
rb_define_singleton_method(mDictionary, "add_entropy_tables_from_buffer", dict_s_add_entropy_tables_from_buffer, 3);
|
497
|
+
rb_define_singleton_method(mDictionary, "getid", dict_s_getid, 1);
|
498
|
+
}
|
499
|
+
|
500
|
+
/*
|
501
|
+
* module Zstd::ContextLess
|
502
|
+
*/
|
503
|
+
|
504
|
+
static VALUE mContextLess;
|
505
|
+
|
506
|
+
/*
|
507
|
+
* call-seq:
|
508
|
+
* encode(src, dest, maxdest, params)
|
509
|
+
*
|
510
|
+
* [RETURN] dest
|
511
|
+
* [src (string)]
|
512
|
+
* [dest (string)]
|
513
|
+
* [maxdest (integer or nil)]
|
514
|
+
* [params (nil, integer or Zstd::Parameters)]
|
515
|
+
*/
|
516
|
+
static VALUE
|
517
|
+
less_s_encode(VALUE mod, VALUE src, VALUE dest, VALUE maxdest, VALUE predict, VALUE params)
|
518
|
+
{
|
519
|
+
const char *q;
|
520
|
+
size_t qsize;
|
521
|
+
aux_string_pointer(src, &q, &qsize);
|
522
|
+
|
523
|
+
char *r;
|
524
|
+
size_t rsize = (NIL_P(maxdest)) ? ZSTD_compressBound(qsize) : NUM2SIZET(maxdest);
|
525
|
+
aux_string_expand_pointer(dest, &r, rsize);
|
526
|
+
rb_obj_infect(dest, src);
|
527
|
+
|
528
|
+
const char *d;
|
529
|
+
size_t dsize;
|
530
|
+
aux_string_pointer_with_nil(predict, &d, &dsize);
|
531
|
+
rb_obj_infect(dest, predict);
|
532
|
+
|
533
|
+
if (extzstd_params_p(params)) {
|
534
|
+
/*
|
535
|
+
* ZSTDLIB_API size_t ZSTD_compress_advanced(
|
536
|
+
* ZSTD_CCtx* ctx,
|
537
|
+
* void* dst, size_t dstCapacity,
|
538
|
+
* const void* src, size_t srcSize,
|
539
|
+
* const void* dict,size_t dictSize,
|
540
|
+
* ZSTD_parameters params);
|
541
|
+
*/
|
542
|
+
ZSTD_CCtx *zstd = ZSTD_createCCtx();
|
543
|
+
size_t s = ZSTD_compress_advanced(zstd, r, rsize, q, qsize, d, dsize, *extzstd_getparams(params));
|
544
|
+
ZSTD_freeCCtx(zstd);
|
545
|
+
extzstd_check_error(s);
|
546
|
+
rb_str_set_len(dest, s);
|
547
|
+
return dest;
|
548
|
+
} else {
|
549
|
+
/*
|
550
|
+
* ZSTDLIB_API size_t ZSTD_compress_usingDict(
|
551
|
+
* ZSTD_CCtx* ctx,
|
552
|
+
* void* dst, size_t dstCapacity,
|
553
|
+
* const void* src, size_t srcSize,
|
554
|
+
* const void* dict,size_t dictSize,
|
555
|
+
* int compressionLevel);
|
556
|
+
*/
|
557
|
+
ZSTD_CCtx *zstd = ZSTD_createCCtx();
|
558
|
+
size_t s = ZSTD_compress_usingDict(zstd, r, rsize, q, qsize, d, dsize, aux_num2int(params, 0));
|
559
|
+
ZSTD_freeCCtx(zstd);
|
560
|
+
extzstd_check_error(s);
|
561
|
+
rb_str_set_len(dest, s);
|
562
|
+
return dest;
|
563
|
+
}
|
564
|
+
}
|
565
|
+
|
566
|
+
/*
|
567
|
+
* call-seq:
|
568
|
+
* decode(src, dest, maxdest)
|
569
|
+
*
|
570
|
+
* [RETURN] dest
|
571
|
+
* [src (string)]
|
572
|
+
* [dest (string)]
|
573
|
+
* [maxdest (integer or nil)]
|
574
|
+
*/
|
575
|
+
static VALUE
|
576
|
+
less_s_decode(VALUE mod, VALUE src, VALUE dest, VALUE maxdest, VALUE predict)
|
577
|
+
{
|
578
|
+
const char *q;
|
579
|
+
size_t qsize;
|
580
|
+
aux_string_pointer(src, &q, &qsize);
|
581
|
+
|
582
|
+
char *r;
|
583
|
+
size_t rsize = (NIL_P(maxdest)) ? ZSTD_getDecompressedSize(q, qsize) : NUM2SIZET(maxdest);
|
584
|
+
aux_string_expand_pointer(dest, &r, rsize);
|
585
|
+
rb_obj_infect(dest, src);
|
586
|
+
|
587
|
+
const char *d;
|
588
|
+
size_t dsize;
|
589
|
+
aux_string_pointer_with_nil(predict, &d, &dsize);
|
590
|
+
rb_obj_infect(dest, predict);
|
591
|
+
|
592
|
+
ZSTD_DCtx *z = ZSTD_createDCtx();
|
593
|
+
size_t s = ZSTD_decompress_usingDict(z, r, rsize, q, qsize, d, dsize);
|
594
|
+
ZSTD_freeDCtx(z);
|
595
|
+
extzstd_check_error(s);
|
596
|
+
rb_str_set_len(dest, s);
|
597
|
+
|
598
|
+
return dest;
|
528
599
|
}
|
529
600
|
|
601
|
+
static void
|
602
|
+
init_contextless(void)
|
603
|
+
{
|
604
|
+
mContextLess = rb_define_module_under(extzstd_mZstd, "ContextLess");
|
605
|
+
rb_define_singleton_method(mContextLess, "encode", less_s_encode, 5);
|
606
|
+
rb_define_singleton_method(mContextLess, "decode", less_s_decode, 4);
|
607
|
+
}
|
530
608
|
|
531
609
|
/*
|
532
610
|
* library initializer
|
533
611
|
*/
|
534
612
|
|
535
|
-
void
|
613
|
+
RBEXT_API void
|
536
614
|
Init_extzstd(void)
|
537
615
|
{
|
616
|
+
id_initialize = rb_intern("initialize");
|
617
|
+
id_error_code = rb_intern("error_code");
|
618
|
+
|
538
619
|
extzstd_mZstd = rb_define_module("Zstd");
|
539
620
|
|
540
621
|
init_libver();
|
541
622
|
init_error();
|
542
623
|
init_constants();
|
543
|
-
|
624
|
+
init_params();
|
544
625
|
init_dictionary();
|
545
|
-
|
626
|
+
init_contextless();
|
627
|
+
extzstd_init_stream();
|
546
628
|
}
|