@@ -113,6 +113,27 @@ rb_streaming_decompress_decompress(VALUE obj, VALUE src)
113113 return result ;
114114}
115115
116+ static VALUE
117+ rb_streaming_decompress_decompress2 (VALUE obj , VALUE src )
118+ {
119+ StringValue (src );
120+ const char * input_data = RSTRING_PTR (src );
121+ size_t input_size = RSTRING_LEN (src );
122+ ZSTD_inBuffer input = { input_data , input_size , 0 };
123+
124+ struct streaming_decompress_t * sd ;
125+ TypedData_Get_Struct (obj , struct streaming_decompress_t , & streaming_decompress_type , sd );
126+ const char * output_data = RSTRING_PTR (sd -> buf );
127+ VALUE result = rb_str_new (0 , 0 );
128+ ZSTD_outBuffer output = { (void * )output_data , sd -> buf_size , 0 };
129+ size_t const ret = zstd_stream_decompress (sd -> dctx , & output , & input , false);
130+ if (ZSTD_isError (ret )) {
131+ rb_raise (rb_eRuntimeError , "decompress error error code: %s" , ZSTD_getErrorName (ret ));
132+ }
133+ rb_str_cat (result , output .dst , output .pos );
134+ return rb_ary_new_from_args (3 , UINT2NUM (ret ), result , ULONG2NUM (input .pos ));
135+ }
136+
116137extern VALUE rb_mZstd , cStreamingDecompress ;
117138void
118139zstd_ruby_streaming_decompress_init (void )
@@ -121,4 +142,5 @@ zstd_ruby_streaming_decompress_init(void)
121142 rb_define_alloc_func (cStreamingDecompress , rb_streaming_decompress_allocate );
122143 rb_define_method (cStreamingDecompress , "initialize" , rb_streaming_decompress_initialize , -1 );
123144 rb_define_method (cStreamingDecompress , "decompress" , rb_streaming_decompress_decompress , 1 );
145+ rb_define_method (cStreamingDecompress , "decompress2" , rb_streaming_decompress_decompress2 , 1 );
124146}
0 commit comments