zstd-ruby 1.5.4.0 → 1.5.4.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5025a83454e6841492b428638df26d5bbacfae564e3e0dcaabce5955e2bd3688
4
- data.tar.gz: f50bf1bb09958e116917344fddaa8bf1d45088894769d791bbe3664a74a3b907
3
+ metadata.gz: 20843652df6bf499ef8cbf75a75e9b9c2bf1a445d7dc1ae9fc48faa07e8af768
4
+ data.tar.gz: 52939d134568bf22f7633a28624ebb1574b72cc33711759c62da8a7971828a57
5
5
  SHA512:
6
- metadata.gz: c754293689a65269f3f262605ad07cd72c0e162dde804dab2d0e144b67c251cbeaf5306db451ac15878388113617d09aaef5c065349c893b233804d6f0883812
7
- data.tar.gz: f2bc576e57766984c1d81e05f69a499461ffc437383f084d6cd83f22f3621f368a9ee668ad786165d537780112b42ade0c7d3e43b8fb35ac77634fbbad12d5c8
6
+ metadata.gz: 4eee9c6badff4d9cbd516b94ec5ec488bff58d25a59ec9a6de9e7aa5afcb117b8eb6e69bc319e9dd8a8f69b8c5dbd1504e0001cf7e312b27fad8c0ed63bdcf64
7
+ data.tar.gz: 518fffdbde3535b6e104d0733529db99db98304b99f3b0cc5d27edfabfe3c5922d05d0e0e4cb7cf1bc051dfb4651a886921b3faf5a61b24dec2a99f472150551
data/README.md CHANGED
@@ -10,7 +10,7 @@ See https://github.com/facebook/zstd
10
10
  Fork from https://github.com/jarredholman/ruby-zstd.
11
11
 
12
12
  ## Zstd version
13
- v1.5.2 (https://github.com/facebook/zstd/tree/v1.5.2)
13
+ v1.5.4 (https://github.com/facebook/zstd/tree/v1.5.4)
14
14
 
15
15
  ## Installation
16
16
 
@@ -87,6 +87,14 @@ result << stream.decompress(cstr[0, 10])
87
87
  result << stream.decompress(cstr[10..-1])
88
88
  ```
89
89
 
90
+ ### Skippable flame
91
+
92
+ ```ruby
93
+ compressed_data_with_skippable_frame = Zstd.write_skippable_frame(compressed_data, "sample data")
94
+
95
+ Zstd.read_skippable_frame(compressed_data_with_skippable_frame)
96
+ # => "sample data"
97
+ ```
90
98
 
91
99
  ## JRuby
92
100
  This gem does not support JRuby.
@@ -1,6 +1,6 @@
1
1
  require "mkmf"
2
2
 
3
- $CFLAGS = '-I. -O3 -std=c99'
3
+ $CFLAGS = '-I. -O3 -std=c99 -DZSTD_STATIC_LINKING_ONLY'
4
4
  $CPPFLAGS += " -fdeclspec" if CONFIG['CXX'] =~ /clang/
5
5
 
6
6
  Dir.chdir File.expand_path('..', __FILE__) do
data/ext/zstdruby/main.c CHANGED
@@ -1,6 +1,7 @@
1
1
  #include <common.h>
2
2
  VALUE rb_mZstd;
3
3
  void zstd_ruby_init(void);
4
+ void zstd_ruby_skippable_frame_init(void);
4
5
  void zstd_ruby_streaming_compress_init(void);
5
6
  void zstd_ruby_streaming_decompress_init(void);
6
7
 
@@ -13,6 +14,7 @@ Init_zstdruby(void)
13
14
 
14
15
  rb_mZstd = rb_define_module("Zstd");
15
16
  zstd_ruby_init();
17
+ zstd_ruby_skippable_frame_init();
16
18
  zstd_ruby_streaming_compress_init();
17
19
  zstd_ruby_streaming_decompress_init();
18
20
  }
@@ -0,0 +1,63 @@
1
+ #include <common.h>
2
+
3
+ extern VALUE rb_mZstd;
4
+
5
+ static VALUE rb_write_skippable_frame(int argc, VALUE *argv, VALUE self)
6
+ {
7
+ VALUE input_value;
8
+ VALUE skip_value;
9
+ VALUE kwargs;
10
+ rb_scan_args(argc, argv, "2:", &input_value, &skip_value, &kwargs);
11
+
12
+ ID kwargs_keys[1];
13
+ kwargs_keys[0] = rb_intern("magic_variant");
14
+ VALUE kwargs_values[1];
15
+ rb_get_kwargs(kwargs, kwargs_keys, 0, 1, kwargs_values);
16
+ unsigned magic_variant = (kwargs_values[0] != Qundef) ? (NUM2INT(kwargs_values[0])) : 0;
17
+
18
+ StringValue(input_value);
19
+ StringValue(skip_value);
20
+ char* input_data = RSTRING_PTR(input_value);
21
+ size_t input_size = RSTRING_LEN(input_value);
22
+ char* skip_data = RSTRING_PTR(skip_value);
23
+ size_t skip_size = RSTRING_LEN(skip_value);
24
+
25
+ size_t dst_size = input_size + ZSTD_SKIPPABLEHEADERSIZE + skip_size;
26
+ VALUE output = rb_str_new(input_data, dst_size);
27
+ char* output_data = RSTRING_PTR(output);
28
+ size_t output_size = ZSTD_writeSkippableFrame((void*)output_data, dst_size, (const void*)skip_data, skip_size, magic_variant);
29
+ if (ZSTD_isError(output_size)) {
30
+ rb_raise(rb_eRuntimeError, "%s: %s", "write skippable frame failed", ZSTD_getErrorName(output_size));
31
+ }
32
+
33
+ rb_str_resize(output, output_size);
34
+ return output;
35
+ }
36
+
37
+ static VALUE rb_read_skippable_frame(VALUE self, VALUE input_value)
38
+ {
39
+ char* input_data = RSTRING_PTR(input_value);
40
+ size_t input_size = RSTRING_LEN(input_value);
41
+
42
+ if (ZSTD_isSkippableFrame(input_data, input_size) == 0) {
43
+ return Qnil;
44
+ }
45
+ // ref https://github.com/facebook/zstd/blob/321490cd5b9863433b3d44816d04012874e5ecdb/tests/fuzzer.c#L2096
46
+ size_t const skipLen = 129 * 1024;
47
+ VALUE output = rb_str_new(NULL, skipLen);
48
+ char* output_data = RSTRING_PTR(output);
49
+ unsigned readMagic;
50
+ size_t output_size = ZSTD_readSkippableFrame((void*)output_data, skipLen, &readMagic, (const void*)input_data, input_size);
51
+ if (ZSTD_isError(output_size)) {
52
+ rb_raise(rb_eRuntimeError, "%s: %s", "read skippable frame failed", ZSTD_getErrorName(output_size));
53
+ }
54
+ rb_str_resize(output, output_size);
55
+ return output;
56
+ }
57
+
58
+ void
59
+ zstd_ruby_skippable_frame_init(void)
60
+ {
61
+ rb_define_module_function(rb_mZstd, "write_skippable_frame", rb_write_skippable_frame, -1);
62
+ rb_define_module_function(rb_mZstd, "read_skippable_frame", rb_read_skippable_frame, 1);
63
+ }
@@ -1,3 +1,3 @@
1
1
  module Zstd
2
- VERSION = "1.5.4.0"
2
+ VERSION = "1.5.4.1"
3
3
  end
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.4.0
4
+ version: 1.5.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - SpringMT
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-02-10 00:00:00.000000000 Z
11
+ date: 2023-03-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -156,6 +156,7 @@ files:
156
156
  - ext/zstdruby/libzstd/zstd.h
157
157
  - ext/zstdruby/libzstd/zstd_errors.h
158
158
  - ext/zstdruby/main.c
159
+ - ext/zstdruby/skippable_frame.c
159
160
  - ext/zstdruby/streaming_compress.c
160
161
  - ext/zstdruby/streaming_compress.h
161
162
  - ext/zstdruby/streaming_decompress.c