1
- #include <common.h>
2
- #include <streaming_compress.h>
1
+ #include "common.h"
3
2
4
3
struct streaming_compress_t {
5
4
ZSTD_CCtx * ctx ;
@@ -71,14 +70,9 @@ rb_streaming_compress_allocate(VALUE klass)
71
70
static VALUE
72
71
rb_streaming_compress_initialize (int argc , VALUE * argv , VALUE obj )
73
72
{
73
+ VALUE kwargs ;
74
74
VALUE compression_level_value ;
75
- rb_scan_args (argc , argv , "01" , & compression_level_value );
76
- int compression_level = convert_compression_level (compression_level_value );
77
-
78
- ID kwargs_keys [1 ];
79
- kwargs_keys [0 ] = rb_intern ("dict" );
80
- VALUE kwargs_values [1 ];
81
- rb_get_kwargs (kwargs , kwargs_keys , 0 , 1 , kwargs_values );
75
+ rb_scan_args (argc , argv , "01:" , & compression_level_value , & kwargs );
82
76
83
77
struct streaming_compress_t * sc ;
84
78
TypedData_Get_Struct (obj , struct streaming_compress_t , & streaming_compress_type , sc );
@@ -88,15 +82,8 @@ rb_streaming_compress_initialize(int argc, VALUE *argv, VALUE obj)
88
82
if (ctx == NULL ) {
89
83
rb_raise (rb_eRuntimeError , "%s" , "ZSTD_createCCtx error" );
90
84
}
91
- if (kwargs_values [0 ] != Qundef && kwargs_values [0 ] != Qnil ) {
92
- char * dict_buffer = RSTRING_PTR (kwargs_values [0 ]);
93
- size_t dict_size = RSTRING_LEN (kwargs_values [0 ]);
94
- size_t load_dict_ret = ZSTD_CCtx_loadDictionary (ctx , dict_buffer , dict_size );
95
- if (ZSTD_isError (load_dict_ret )) {
96
- rb_raise (rb_eRuntimeError , "%s" , "ZSTD_CCtx_loadDictionary failed" );
97
- }
98
- }
99
- ZSTD_CCtx_setParameter (ctx , ZSTD_c_compressionLevel , compression_level );
85
+ set_compress_params (ctx , compression_level_value , kwargs );
86
+
100
87
sc -> ctx = ctx ;
101
88
sc -> buf = rb_str_new (NULL , buffOutSize );
102
89
sc -> buf_size = buffOutSize ;
@@ -119,7 +106,7 @@ no_compress(struct streaming_compress_t* sc, ZSTD_EndDirective endOp)
119
106
do {
120
107
ZSTD_outBuffer output = { (void * )output_data , sc -> buf_size , 0 };
121
108
122
- size_t const ret = ZSTD_compressStream2 (sc -> ctx , & output , & input , endOp );
109
+ size_t const ret = zstd_compress (sc -> ctx , & output , & input , endOp );
123
110
if (ZSTD_isError (ret )) {
124
111
rb_raise (rb_eRuntimeError , "flush error error code: %s" , ZSTD_getErrorName (ret ));
125
112
}
@@ -143,7 +130,7 @@ rb_streaming_compress_compress(VALUE obj, VALUE src)
143
130
VALUE result = rb_str_new (0 , 0 );
144
131
while (input .pos < input .size ) {
145
132
ZSTD_outBuffer output = { (void * )output_data , sc -> buf_size , 0 };
146
- size_t const ret = ZSTD_compressStream2 (sc -> ctx , & output , & input , ZSTD_e_continue );
133
+ size_t const ret = zstd_compress (sc -> ctx , & output , & input , ZSTD_e_continue );
147
134
if (ZSTD_isError (ret )) {
148
135
rb_raise (rb_eRuntimeError , "compress error error code: %s" , ZSTD_getErrorName (ret ));
149
136
}
@@ -170,7 +157,7 @@ rb_streaming_compress_write(int argc, VALUE *argv, VALUE obj)
170
157
ZSTD_inBuffer input = { input_data , input_size , 0 };
171
158
172
159
while (input .pos < input .size ) {
173
- size_t const ret = ZSTD_compressStream2 (sc -> ctx , & output , & input , ZSTD_e_continue );
160
+ size_t const ret = zstd_compress (sc -> ctx , & output , & input , ZSTD_e_continue );
174
161
if (ZSTD_isError (ret )) {
175
162
rb_raise (rb_eRuntimeError , "compress error error code: %s" , ZSTD_getErrorName (ret ));
176
163
}
0 commit comments