zstd-ruby 1.5.6.4 → 1.5.6.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +39 -0
- data/ext/zstdruby/common.h +68 -6
- data/ext/zstdruby/streaming_decompress.c +1 -1
- data/ext/zstdruby/zstdruby.c +11 -11
- data/lib/zstd-ruby/version.rb +1 -1
- data/lib/zstd-ruby.rb +2 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1fe1a5bcfa102673b36ea9a48096636faa76535095211998cddfe316775a3d78
|
4
|
+
data.tar.gz: e2a96d0d1d2bdda0bc3d34080df219aeaa8c5274a2dac7a838730fce54ebe4f6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6bdffd7e5b2d824fdf5ebad116ef4b965c4d4d2a77898df5a51623020db6fddf0e4562aa4d80de7f8978fa5f557ce85e56d19042667c379b3ac97c3a274a9d11
|
7
|
+
data.tar.gz: 639a3d64cf8a8fa36a10cf180560a4102516d4da21e3100c1cdd724732fb583449c828ac4eeef6f9bad89c2f22467f7adf80b083116121ccff8d356c58246966
|
data/README.md
CHANGED
@@ -127,6 +127,45 @@ Zstd.read_skippable_frame(compressed_data_with_skippable_frame)
|
|
127
127
|
# => "sample data"
|
128
128
|
```
|
129
129
|
|
130
|
+
### Stream Writer and Reader Wrapper
|
131
|
+
**EXPERIMENTAL**
|
132
|
+
|
133
|
+
* These features are experimental and may be subject to API changes in future releases.
|
134
|
+
* There may be performance and compatibility issues, so extensive testing is required before production use.
|
135
|
+
* If you have any questions, encounter bugs, or have suggestions, please report them via [GitHub issues](https://github.com/SpringMT/zstd-ruby/issues).
|
136
|
+
|
137
|
+
#### Zstd::StreamWriter
|
138
|
+
|
139
|
+
```ruby
|
140
|
+
require 'stringio'
|
141
|
+
require 'zstd-ruby'
|
142
|
+
|
143
|
+
io = StringIO.new
|
144
|
+
stream = Zstd::StreamWriter.new(io)
|
145
|
+
stream.write("abc")
|
146
|
+
stream.finish
|
147
|
+
|
148
|
+
io.rewind
|
149
|
+
# Retrieve the compressed data
|
150
|
+
compressed_data = io.read
|
151
|
+
```
|
152
|
+
|
153
|
+
#### Zstd::StreamReader
|
154
|
+
|
155
|
+
```ruby
|
156
|
+
require 'stringio'
|
157
|
+
require 'zstd-ruby' # Add the appropriate require statement if necessary
|
158
|
+
|
159
|
+
io = StringIO.new(compressed_data)
|
160
|
+
reader = Zstd::StreamReader.new(io)
|
161
|
+
|
162
|
+
# Read and output the decompressed data
|
163
|
+
puts reader.read(10) # 'abc'
|
164
|
+
puts reader.read(10) # 'def'
|
165
|
+
puts reader.read(10) # '' (end of data)
|
166
|
+
```
|
167
|
+
|
168
|
+
|
130
169
|
## JRuby
|
131
170
|
This gem does not support JRuby.
|
132
171
|
|
data/ext/zstdruby/common.h
CHANGED
@@ -74,6 +74,37 @@ static size_t zstd_stream_compress(ZSTD_CCtx* const ctx, ZSTD_outBuffer* output,
|
|
74
74
|
#endif
|
75
75
|
}
|
76
76
|
|
77
|
+
struct compress_params {
|
78
|
+
ZSTD_CCtx* ctx;
|
79
|
+
char* output_data;
|
80
|
+
size_t output_size;
|
81
|
+
char* input_data;
|
82
|
+
size_t input_size;
|
83
|
+
size_t ret;
|
84
|
+
};
|
85
|
+
|
86
|
+
static void* compress_wrapper(void* args)
|
87
|
+
{
|
88
|
+
struct compress_params* params = args;
|
89
|
+
params->ret = ZSTD_compress2(params->ctx ,params->output_data, params->output_size, params->input_data, params->input_size);
|
90
|
+
return NULL;
|
91
|
+
}
|
92
|
+
|
93
|
+
static size_t zstd_compress(ZSTD_CCtx* const ctx, char* output_data, size_t output_size, char* input_data, size_t input_size, bool gvl)
|
94
|
+
{
|
95
|
+
#ifdef HAVE_RUBY_THREAD_H
|
96
|
+
if (gvl) {
|
97
|
+
return ZSTD_compress2(ctx , output_data, output_size, input_data, input_size);
|
98
|
+
} else {
|
99
|
+
struct compress_params params = { ctx, output_data, output_size, input_data, input_size };
|
100
|
+
rb_thread_call_without_gvl(compress_wrapper, ¶ms, NULL, NULL);
|
101
|
+
return params.ret;
|
102
|
+
}
|
103
|
+
#else
|
104
|
+
return ZSTD_compress2(ctx , output_data, output_size, input_data, input_size);
|
105
|
+
#endif
|
106
|
+
}
|
107
|
+
|
77
108
|
static void set_decompress_params(ZSTD_DCtx* const dctx, VALUE kwargs)
|
78
109
|
{
|
79
110
|
ID kwargs_keys[1];
|
@@ -92,28 +123,28 @@ static void set_decompress_params(ZSTD_DCtx* const dctx, VALUE kwargs)
|
|
92
123
|
}
|
93
124
|
}
|
94
125
|
|
95
|
-
struct
|
126
|
+
struct stream_decompress_params {
|
96
127
|
ZSTD_DCtx* dctx;
|
97
128
|
ZSTD_outBuffer* output;
|
98
129
|
ZSTD_inBuffer* input;
|
99
130
|
size_t ret;
|
100
131
|
};
|
101
132
|
|
102
|
-
static void*
|
133
|
+
static void* stream_decompress_wrapper(void* args)
|
103
134
|
{
|
104
|
-
struct
|
135
|
+
struct stream_decompress_params* params = args;
|
105
136
|
params->ret = ZSTD_decompressStream(params->dctx, params->output, params->input);
|
106
137
|
return NULL;
|
107
138
|
}
|
108
139
|
|
109
|
-
static size_t
|
140
|
+
static size_t zstd_stream_decompress(ZSTD_DCtx* const dctx, ZSTD_outBuffer* output, ZSTD_inBuffer* input, bool gvl)
|
110
141
|
{
|
111
142
|
#ifdef HAVE_RUBY_THREAD_H
|
112
143
|
if (gvl) {
|
113
144
|
return ZSTD_decompressStream(dctx, output, input);
|
114
145
|
} else {
|
115
|
-
struct
|
116
|
-
rb_thread_call_without_gvl(
|
146
|
+
struct stream_decompress_params params = { dctx, output, input };
|
147
|
+
rb_thread_call_without_gvl(stream_decompress_wrapper, ¶ms, NULL, NULL);
|
117
148
|
return params.ret;
|
118
149
|
}
|
119
150
|
#else
|
@@ -121,4 +152,35 @@ static size_t zstd_decompress(ZSTD_DCtx* const dctx, ZSTD_outBuffer* output, ZST
|
|
121
152
|
#endif
|
122
153
|
}
|
123
154
|
|
155
|
+
struct decompress_params {
|
156
|
+
ZSTD_DCtx* dctx;
|
157
|
+
char* output_data;
|
158
|
+
size_t output_size;
|
159
|
+
char* input_data;
|
160
|
+
size_t input_size;
|
161
|
+
size_t ret;
|
162
|
+
};
|
163
|
+
|
164
|
+
static void* decompress_wrapper(void* args)
|
165
|
+
{
|
166
|
+
struct decompress_params* params = args;
|
167
|
+
params->ret = ZSTD_decompressDCtx(params->dctx, params->output_data, params->output_size, params->input_data, params->input_size);
|
168
|
+
return NULL;
|
169
|
+
}
|
170
|
+
|
171
|
+
static size_t zstd_decompress(ZSTD_DCtx* const dctx, char* output_data, size_t output_size, char* input_data, size_t input_size, bool gvl)
|
172
|
+
{
|
173
|
+
#ifdef HAVE_RUBY_THREAD_H
|
174
|
+
if (gvl) {
|
175
|
+
return ZSTD_decompressDCtx(dctx, output_data, output_size, input_data, input_size);
|
176
|
+
} else {
|
177
|
+
struct decompress_params params = { dctx, output_data, output_size, input_data, input_size };
|
178
|
+
rb_thread_call_without_gvl(decompress_wrapper, ¶ms, NULL, NULL);
|
179
|
+
return params.ret;
|
180
|
+
}
|
181
|
+
#else
|
182
|
+
return ZSTD_decompressDCtx(dctx, output_data, output_size, input_data, input_size);
|
183
|
+
#endif
|
184
|
+
}
|
185
|
+
|
124
186
|
#endif /* ZSTD_RUBY_H */
|
@@ -104,7 +104,7 @@ rb_streaming_decompress_decompress(VALUE obj, VALUE src)
|
|
104
104
|
VALUE result = rb_str_new(0, 0);
|
105
105
|
while (input.pos < input.size) {
|
106
106
|
ZSTD_outBuffer output = { (void*)output_data, sd->buf_size, 0 };
|
107
|
-
size_t const ret =
|
107
|
+
size_t const ret = zstd_stream_decompress(sd->dctx, &output, &input, false);
|
108
108
|
if (ZSTD_isError(ret)) {
|
109
109
|
rb_raise(rb_eRuntimeError, "decompress error error code: %s", ZSTD_getErrorName(ret));
|
110
110
|
}
|
data/ext/zstdruby/zstdruby.c
CHANGED
@@ -26,11 +26,11 @@ static VALUE rb_compress(int argc, VALUE *argv, VALUE self)
|
|
26
26
|
char* input_data = RSTRING_PTR(input_value);
|
27
27
|
size_t input_size = RSTRING_LEN(input_value);
|
28
28
|
|
29
|
-
size_t
|
29
|
+
size_t max_compressed_size = ZSTD_compressBound(input_size);
|
30
30
|
VALUE output = rb_str_new(NULL, max_compressed_size);
|
31
|
-
|
31
|
+
char* output_data = RSTRING_PTR(output);
|
32
32
|
|
33
|
-
size_t const ret =
|
33
|
+
size_t const ret = zstd_compress(ctx, output_data, max_compressed_size, input_data, input_size, false);
|
34
34
|
if (ZSTD_isError(ret)) {
|
35
35
|
rb_raise(rb_eRuntimeError, "compress error error code: %s", ZSTD_getErrorName(ret));
|
36
36
|
}
|
@@ -87,24 +87,24 @@ static VALUE rb_compress_using_dict(int argc, VALUE *argv, VALUE self)
|
|
87
87
|
|
88
88
|
static VALUE decompress_buffered(ZSTD_DCtx* dctx, const char* input_data, size_t input_size)
|
89
89
|
{
|
90
|
-
VALUE output_string = rb_str_new(NULL, 0);
|
91
|
-
ZSTD_outBuffer output = { NULL, 0, 0 };
|
92
|
-
|
93
90
|
ZSTD_inBuffer input = { input_data, input_size, 0 };
|
91
|
+
VALUE result = rb_str_new(0, 0);
|
92
|
+
|
94
93
|
while (input.pos < input.size) {
|
94
|
+
ZSTD_outBuffer output = { NULL, 0, 0 };
|
95
95
|
output.size += ZSTD_DStreamOutSize();
|
96
|
-
|
96
|
+
VALUE output_string = rb_str_new(NULL, output.size);
|
97
97
|
output.dst = RSTRING_PTR(output_string);
|
98
98
|
|
99
|
-
size_t ret =
|
99
|
+
size_t ret = zstd_stream_decompress(dctx, &output, &input, false);
|
100
100
|
if (ZSTD_isError(ret)) {
|
101
101
|
ZSTD_freeDCtx(dctx);
|
102
102
|
rb_raise(rb_eRuntimeError, "%s: %s", "ZSTD_decompressStream failed", ZSTD_getErrorName(ret));
|
103
103
|
}
|
104
|
+
rb_str_cat(result, output.dst, output.pos);
|
104
105
|
}
|
105
|
-
rb_str_resize(output_string, output.pos);
|
106
106
|
ZSTD_freeDCtx(dctx);
|
107
|
-
return
|
107
|
+
return result;
|
108
108
|
}
|
109
109
|
|
110
110
|
static VALUE rb_decompress(int argc, VALUE *argv, VALUE self)
|
@@ -134,7 +134,7 @@ static VALUE rb_decompress(int argc, VALUE *argv, VALUE self)
|
|
134
134
|
VALUE output = rb_str_new(NULL, uncompressed_size);
|
135
135
|
char* output_data = RSTRING_PTR(output);
|
136
136
|
|
137
|
-
size_t const decompress_size =
|
137
|
+
size_t const decompress_size = zstd_decompress(dctx, output_data, uncompressed_size, input_data, input_size, false);
|
138
138
|
if (ZSTD_isError(decompress_size)) {
|
139
139
|
rb_raise(rb_eRuntimeError, "%s: %s", "decompress error", ZSTD_getErrorName(decompress_size));
|
140
140
|
}
|
data/lib/zstd-ruby/version.rb
CHANGED
data/lib/zstd-ruby.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: zstd-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.5.6.
|
4
|
+
version: 1.5.6.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- SpringMT
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-05-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|