zstd-ruby 2.0.3 → 2.0.4

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 65a00efff2063419d15ec39be7fb8f30bc55adae0300544aa05acef44e3c18b7
4
- data.tar.gz: a19e44f78c56c8b6711e6f857bfb9b29a8e05e47d0096b0471799e663e67a90f
3
+ metadata.gz: f9a23c701181eccbc41191787fd658f9bc2d78a449468caff3b106b2bf64173e
4
+ data.tar.gz: addcdf88b39e425cf4090c9b461f33058c62c8ccd77404e70dd6674403c84db9
5
5
  SHA512:
6
- metadata.gz: e9dd0a8b325b42e9ea0438f65a452c5c19f928e5d7848be16ea2cc3d81841d7bf820aa776ff10e717c669c0171ba6e5fc2951fff3771315996c8e483a9af9b85
7
- data.tar.gz: 843ef5641e08729a1519c06a9408cc8b363cbd6c4cfc5d4df57da56ce0d7a7c33c22fa62f6a0ceca0922ebacf83cfb607541dff6788888e93a1cbfd6b13d03be
6
+ metadata.gz: 2c340e8a040207bd0551a634bfe899f904276bb4ddc9e20b5148e888a978b5a4d9d88fcac92914d7fb31acf4e4ffd8345d60871709540d76f0bad9a06b27a2ea
7
+ data.tar.gz: e240f5870f6cd187012d52c181cbe8fdfd0b2a351b896c0d25832153b708e0b241c577153bf789cdf6b6beaafce66fa0d1901e6714b37c54573dcfce67842175
data/README.md CHANGED
@@ -7,8 +7,6 @@ Ruby binding for zstd(Zstandard - Fast real-time compression algorithm)
7
7
 
8
8
  See https://github.com/facebook/zstd
9
9
 
10
- Fork from https://github.com/jarredholman/ruby-zstd.
11
-
12
10
  ## Zstd version
13
11
  [v1.5.7](https://github.com/facebook/zstd/tree/v1.5.7)
14
12
 
@@ -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
 
@@ -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
 
@@ -169,7 +170,7 @@ static VALUE rb_cdict_initialize(int argc, VALUE *argv, VALUE self)
169
170
  VALUE dict;
170
171
  VALUE compression_level_value;
171
172
  rb_scan_args(argc, argv, "11", &dict, &compression_level_value);
172
- int compression_level = convert_compression_level(compression_level_value);
173
+ int compression_level = convert_compression_level(NULL, compression_level_value);
173
174
 
174
175
  StringValue(dict);
175
176
  char* dict_buffer = RSTRING_PTR(dict);
@@ -1,3 +1,3 @@
1
1
  module Zstd
2
- VERSION = "2.0.3"
2
+ VERSION = "2.0.4"
3
3
  end
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.3
4
+ version: 2.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - SpringMT
8
8
  bindir: exe
9
9
  cert_chain: []
10
- date: 2025-11-02 00:00:00.000000000 Z
10
+ date: 2025-12-24 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: bundler