zstd-ruby 2.0.3 → 2.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +0 -2
- data/ext/zstdruby/common.h +8 -2
- data/ext/zstdruby/zstdruby.c +5 -9
- data/lib/zstd-ruby/version.rb +1 -1
- 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: 3c3c7ba2ca27786f539bd8083ec97ae1822a529d075147ef1f12f5b565201a3a
|
|
4
|
+
data.tar.gz: 961f3e60ceb142982e9dadec995b4246e77535abb538250f7c488f1ef2e1dab4
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: a3a8b7e573f0c356d7cfaa72416f7f306ccf4d989f17c3265d648956a869f3fa6e166d57a8f0764da070e46014a07fef46b5a05ca814371df5d1d6f470fc595e
|
|
7
|
+
data.tar.gz: 3014a12287071ba7c4d868313ff63e70f99a026f7b0cd28a6c4d5e70a0c0a13497adf0d984a736ca14d5388739c14a10f1342ff01b49d44ba80f59e49f38197f
|
data/README.md
CHANGED
data/ext/zstdruby/common.h
CHANGED
|
@@ -10,11 +10,17 @@
|
|
|
10
10
|
|
|
11
11
|
extern VALUE rb_cCDict, rb_cDDict;
|
|
12
12
|
|
|
13
|
-
static int convert_compression_level(VALUE compression_level_value)
|
|
13
|
+
static int convert_compression_level(ZSTD_CCtx* ctx, VALUE compression_level_value)
|
|
14
14
|
{
|
|
15
15
|
if (NIL_P(compression_level_value)) {
|
|
16
16
|
return ZSTD_CLEVEL_DEFAULT;
|
|
17
17
|
}
|
|
18
|
+
if (!RB_INTEGER_TYPE_P(compression_level_value)) {
|
|
19
|
+
if (ctx) {
|
|
20
|
+
ZSTD_freeCCtx(ctx);
|
|
21
|
+
}
|
|
22
|
+
rb_raise(rb_eTypeError, "compression level must be an Integer");
|
|
23
|
+
}
|
|
18
24
|
return NUM2INT(compression_level_value);
|
|
19
25
|
}
|
|
20
26
|
|
|
@@ -28,7 +34,7 @@ static void set_compress_params(ZSTD_CCtx* const ctx, VALUE kwargs)
|
|
|
28
34
|
|
|
29
35
|
int compression_level = ZSTD_CLEVEL_DEFAULT;
|
|
30
36
|
if (kwargs_values[0] != Qundef && kwargs_values[0] != Qnil) {
|
|
31
|
-
compression_level = convert_compression_level(kwargs_values[0]);
|
|
37
|
+
compression_level = convert_compression_level(ctx, kwargs_values[0]);
|
|
32
38
|
}
|
|
33
39
|
ZSTD_CCtx_setParameter(ctx, ZSTD_c_compressionLevel, compression_level);
|
|
34
40
|
|
data/ext/zstdruby/zstdruby.c
CHANGED
|
@@ -14,6 +14,8 @@ static VALUE rb_compress(int argc, VALUE *argv, VALUE self)
|
|
|
14
14
|
VALUE kwargs;
|
|
15
15
|
rb_scan_args(argc, argv, "10:", &input_value, &kwargs);
|
|
16
16
|
|
|
17
|
+
StringValue(input_value);
|
|
18
|
+
|
|
17
19
|
ZSTD_CCtx* const ctx = ZSTD_createCCtx();
|
|
18
20
|
if (ctx == NULL) {
|
|
19
21
|
rb_raise(rb_eRuntimeError, "%s", "ZSTD_createCCtx error");
|
|
@@ -21,7 +23,6 @@ static VALUE rb_compress(int argc, VALUE *argv, VALUE self)
|
|
|
21
23
|
|
|
22
24
|
set_compress_params(ctx, kwargs);
|
|
23
25
|
|
|
24
|
-
StringValue(input_value);
|
|
25
26
|
char* input_data = RSTRING_PTR(input_value);
|
|
26
27
|
size_t input_size = RSTRING_LEN(input_value);
|
|
27
28
|
|
|
@@ -30,12 +31,12 @@ static VALUE rb_compress(int argc, VALUE *argv, VALUE self)
|
|
|
30
31
|
char* output_data = RSTRING_PTR(output);
|
|
31
32
|
|
|
32
33
|
size_t const ret = zstd_compress(ctx, output_data, max_compressed_size, input_data, input_size, false);
|
|
34
|
+
ZSTD_freeCCtx(ctx);
|
|
33
35
|
if (ZSTD_isError(ret)) {
|
|
34
36
|
rb_raise(rb_eRuntimeError, "compress error error code: %s", ZSTD_getErrorName(ret));
|
|
35
37
|
}
|
|
36
38
|
rb_str_resize(output, ret);
|
|
37
39
|
|
|
38
|
-
ZSTD_freeCCtx(ctx);
|
|
39
40
|
return output;
|
|
40
41
|
}
|
|
41
42
|
|
|
@@ -77,9 +78,7 @@ static VALUE rb_decompress(int argc, VALUE *argv, VALUE self)
|
|
|
77
78
|
StringValue(input_value);
|
|
78
79
|
|
|
79
80
|
size_t in_size = RSTRING_LEN(input_value);
|
|
80
|
-
const unsigned char *
|
|
81
|
-
unsigned char *in = ALLOC_N(unsigned char, in_size);
|
|
82
|
-
memcpy(in, in_r, in_size);
|
|
81
|
+
const unsigned char *in = (const unsigned char *)RSTRING_PTR(input_value);
|
|
83
82
|
|
|
84
83
|
size_t off = 0;
|
|
85
84
|
const uint32_t ZSTD_MAGIC = 0xFD2FB528U;
|
|
@@ -106,14 +105,12 @@ static VALUE rb_decompress(int argc, VALUE *argv, VALUE self)
|
|
|
106
105
|
if (magic == ZSTD_MAGIC) {
|
|
107
106
|
ZSTD_DCtx *dctx = ZSTD_createDCtx();
|
|
108
107
|
if (!dctx) {
|
|
109
|
-
xfree(in);
|
|
110
108
|
rb_raise(rb_eRuntimeError, "ZSTD_createDCtx failed");
|
|
111
109
|
}
|
|
112
110
|
|
|
113
111
|
VALUE out = decode_one_frame(dctx, in + off, in_size - off, kwargs);
|
|
114
112
|
|
|
115
113
|
ZSTD_freeDCtx(dctx);
|
|
116
|
-
xfree(in);
|
|
117
114
|
RB_GC_GUARD(input_value);
|
|
118
115
|
return out;
|
|
119
116
|
}
|
|
@@ -121,7 +118,6 @@ static VALUE rb_decompress(int argc, VALUE *argv, VALUE self)
|
|
|
121
118
|
off += 1;
|
|
122
119
|
}
|
|
123
120
|
|
|
124
|
-
xfree(in);
|
|
125
121
|
RB_GC_GUARD(input_value);
|
|
126
122
|
rb_raise(rb_eRuntimeError, "not a zstd frame (magic not found)");
|
|
127
123
|
}
|
|
@@ -169,7 +165,7 @@ static VALUE rb_cdict_initialize(int argc, VALUE *argv, VALUE self)
|
|
|
169
165
|
VALUE dict;
|
|
170
166
|
VALUE compression_level_value;
|
|
171
167
|
rb_scan_args(argc, argv, "11", &dict, &compression_level_value);
|
|
172
|
-
int compression_level = convert_compression_level(compression_level_value);
|
|
168
|
+
int compression_level = convert_compression_level(NULL, compression_level_value);
|
|
173
169
|
|
|
174
170
|
StringValue(dict);
|
|
175
171
|
char* dict_buffer = RSTRING_PTR(dict);
|
data/lib/zstd-ruby/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: zstd-ruby
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 2.0.
|
|
4
|
+
version: 2.0.5
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- SpringMT
|
|
8
8
|
bindir: exe
|
|
9
9
|
cert_chain: []
|
|
10
|
-
date:
|
|
10
|
+
date: 2026-01-08 00:00:00.000000000 Z
|
|
11
11
|
dependencies:
|
|
12
12
|
- !ruby/object:Gem::Dependency
|
|
13
13
|
name: bundler
|