@@ -11,16 +11,15 @@ static VALUE zstdVersion(VALUE self)
11
11
static VALUE rb_compress (int argc , VALUE * argv , VALUE self )
12
12
{
13
13
VALUE input_value ;
14
- VALUE compression_level_value ;
15
14
VALUE kwargs ;
16
- rb_scan_args (argc , argv , "11 :" , & input_value , & compression_level_value , & kwargs );
15
+ rb_scan_args (argc , argv , "10 :" , & input_value , & kwargs );
17
16
18
17
ZSTD_CCtx * const ctx = ZSTD_createCCtx ();
19
18
if (ctx == NULL ) {
20
19
rb_raise (rb_eRuntimeError , "%s" , "ZSTD_createCCtx error" );
21
20
}
22
21
23
- set_compress_params (ctx , compression_level_value , kwargs );
22
+ set_compress_params (ctx , kwargs );
24
23
25
24
StringValue (input_value );
26
25
char * input_data = RSTRING_PTR (input_value );
@@ -40,51 +39,6 @@ static VALUE rb_compress(int argc, VALUE *argv, VALUE self)
40
39
return output ;
41
40
}
42
41
43
- static VALUE rb_compress_using_dict (int argc , VALUE * argv , VALUE self )
44
- {
45
- rb_warn ("Zstd.compress_using_dict is deprecated; use Zstd.compress with `dict:` instead." );
46
- VALUE input_value ;
47
- VALUE dict ;
48
- VALUE compression_level_value ;
49
- rb_scan_args (argc , argv , "21" , & input_value , & dict , & compression_level_value );
50
- int compression_level = convert_compression_level (compression_level_value );
51
-
52
- StringValue (input_value );
53
- char * input_data = RSTRING_PTR (input_value );
54
- size_t input_size = RSTRING_LEN (input_value );
55
- size_t max_compressed_size = ZSTD_compressBound (input_size );
56
-
57
- char * dict_buffer = RSTRING_PTR (dict );
58
- size_t dict_size = RSTRING_LEN (dict );
59
-
60
- ZSTD_CDict * const cdict = ZSTD_createCDict (dict_buffer , dict_size , compression_level );
61
- if (cdict == NULL ) {
62
- rb_raise (rb_eRuntimeError , "%s" , "ZSTD_createCDict failed" );
63
- }
64
- ZSTD_CCtx * const ctx = ZSTD_createCCtx ();
65
- if (ctx == NULL ) {
66
- ZSTD_freeCDict (cdict );
67
- rb_raise (rb_eRuntimeError , "%s" , "ZSTD_createCCtx failed" );
68
- }
69
-
70
- VALUE output = rb_str_new (NULL , max_compressed_size );
71
- char * output_data = RSTRING_PTR (output );
72
- size_t const compressed_size = ZSTD_compress_usingCDict (ctx , (void * )output_data , max_compressed_size ,
73
- (void * )input_data , input_size , cdict );
74
-
75
- if (ZSTD_isError (compressed_size )) {
76
- ZSTD_freeCDict (cdict );
77
- ZSTD_freeCCtx (ctx );
78
- rb_raise (rb_eRuntimeError , "%s: %s" , "compress failed" , ZSTD_getErrorName (compressed_size ));
79
- }
80
-
81
- rb_str_resize (output , compressed_size );
82
- ZSTD_freeCDict (cdict );
83
- ZSTD_freeCCtx (ctx );
84
- return output ;
85
- }
86
-
87
-
88
42
static VALUE decompress_buffered (ZSTD_DCtx * dctx , const char * input_data , size_t input_size )
89
43
{
90
44
ZSTD_inBuffer input = { input_data , input_size , 0 };
@@ -142,59 +96,6 @@ static VALUE rb_decompress(int argc, VALUE *argv, VALUE self)
142
96
return output ;
143
97
}
144
98
145
- static VALUE rb_decompress_using_dict (int argc , VALUE * argv , VALUE self )
146
- {
147
- rb_warn ("Zstd.decompress_using_dict is deprecated; use Zstd.decompress with `dict:` instead." );
148
- VALUE input_value ;
149
- VALUE dict ;
150
- rb_scan_args (argc , argv , "20" , & input_value , & dict );
151
-
152
- StringValue (input_value );
153
- char * input_data = RSTRING_PTR (input_value );
154
- size_t input_size = RSTRING_LEN (input_value );
155
-
156
- char * dict_buffer = RSTRING_PTR (dict );
157
- size_t dict_size = RSTRING_LEN (dict );
158
- ZSTD_DDict * const ddict = ZSTD_createDDict (dict_buffer , dict_size );
159
- if (ddict == NULL ) {
160
- rb_raise (rb_eRuntimeError , "%s" , "ZSTD_createDDict failed" );
161
- }
162
- unsigned const expected_dict_id = ZSTD_getDictID_fromDDict (ddict );
163
- unsigned const actual_dict_id = ZSTD_getDictID_fromFrame (input_data , input_size );
164
- if (expected_dict_id != actual_dict_id ) {
165
- ZSTD_freeDDict (ddict );
166
- rb_raise (rb_eRuntimeError , "DictID mismatch" );
167
- }
168
-
169
- ZSTD_DCtx * const ctx = ZSTD_createDCtx ();
170
- if (ctx == NULL ) {
171
- ZSTD_freeDDict (ddict );
172
- rb_raise (rb_eRuntimeError , "%s" , "ZSTD_createDCtx failed" );
173
- }
174
-
175
- unsigned long long const uncompressed_size = ZSTD_getFrameContentSize (input_data , input_size );
176
- if (uncompressed_size == ZSTD_CONTENTSIZE_ERROR ) {
177
- ZSTD_freeDDict (ddict );
178
- ZSTD_freeDCtx (ctx );
179
- rb_raise (rb_eRuntimeError , "%s: %s" , "not compressed by zstd" , ZSTD_getErrorName (uncompressed_size ));
180
- }
181
- if (uncompressed_size == ZSTD_CONTENTSIZE_UNKNOWN ) {
182
- return decompress_buffered (ctx , input_data , input_size );
183
- }
184
-
185
- VALUE output = rb_str_new (NULL , uncompressed_size );
186
- char * output_data = RSTRING_PTR (output );
187
- size_t const decompress_size = ZSTD_decompress_usingDDict (ctx , output_data , uncompressed_size , input_data , input_size , ddict );
188
- if (ZSTD_isError (decompress_size )) {
189
- ZSTD_freeDDict (ddict );
190
- ZSTD_freeDCtx (ctx );
191
- rb_raise (rb_eRuntimeError , "%s: %s" , "decompress error" , ZSTD_getErrorName (decompress_size ));
192
- }
193
- ZSTD_freeDDict (ddict );
194
- ZSTD_freeDCtx (ctx );
195
- return output ;
196
- }
197
-
198
99
static void free_cdict (void * dict )
199
100
{
200
101
ZSTD_freeCDict (dict );
@@ -284,9 +185,7 @@ zstd_ruby_init(void)
284
185
{
285
186
rb_define_module_function (rb_mZstd , "zstd_version" , zstdVersion , 0 );
286
187
rb_define_module_function (rb_mZstd , "compress" , rb_compress , -1 );
287
- rb_define_module_function (rb_mZstd , "compress_using_dict" , rb_compress_using_dict , -1 );
288
188
rb_define_module_function (rb_mZstd , "decompress" , rb_decompress , -1 );
289
- rb_define_module_function (rb_mZstd , "decompress_using_dict" , rb_decompress_using_dict , -1 );
290
189
291
190
rb_define_alloc_func (rb_cCDict , rb_cdict_alloc );
292
191
rb_define_private_method (rb_cCDict , "initialize" , rb_cdict_initialize , -1 );
0 commit comments