zstd-ruby 1.5.4.0 → 1.5.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +10 -2
- data/ext/zstdruby/extconf.rb +1 -1
- data/ext/zstdruby/libzstd/common/allocations.h +55 -0
- data/ext/zstdruby/libzstd/common/bits.h +30 -5
- data/ext/zstdruby/libzstd/common/bitstream.h +1 -1
- data/ext/zstdruby/libzstd/common/compiler.h +4 -0
- data/ext/zstdruby/libzstd/common/pool.c +1 -1
- data/ext/zstdruby/libzstd/common/threading.c +1 -1
- data/ext/zstdruby/libzstd/common/zstd_common.c +0 -35
- data/ext/zstdruby/libzstd/common/zstd_internal.h +0 -5
- data/ext/zstdruby/libzstd/compress/zstd_compress.c +209 -104
- data/ext/zstdruby/libzstd/compress/zstd_compress_internal.h +67 -13
- data/ext/zstdruby/libzstd/compress/zstd_cwksp.h +123 -59
- data/ext/zstdruby/libzstd/compress/zstd_lazy.c +92 -62
- data/ext/zstdruby/libzstd/compress/zstd_opt.c +2 -0
- data/ext/zstdruby/libzstd/compress/zstdmt_compress.c +5 -4
- data/ext/zstdruby/libzstd/decompress/huf_decompress.c +4 -4
- data/ext/zstdruby/libzstd/decompress/zstd_ddict.c +1 -0
- data/ext/zstdruby/libzstd/decompress/zstd_decompress.c +41 -38
- data/ext/zstdruby/libzstd/decompress/zstd_decompress_block.c +16 -17
- data/ext/zstdruby/libzstd/decompress/zstd_decompress_block.h +5 -0
- data/ext/zstdruby/libzstd/dictBuilder/zdict.c +2 -2
- data/ext/zstdruby/libzstd/zstd.h +258 -212
- data/ext/zstdruby/main.c +2 -0
- data/ext/zstdruby/skippable_frame.c +63 -0
- data/lib/zstd-ruby/version.rb +1 -1
- metadata +4 -2
@@ -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
|
+
}
|
data/lib/zstd-ruby/version.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.
|
4
|
+
version: 1.5.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- SpringMT
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-04-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -87,6 +87,7 @@ files:
|
|
87
87
|
- bin/setup
|
88
88
|
- ext/zstdruby/common.h
|
89
89
|
- ext/zstdruby/extconf.rb
|
90
|
+
- ext/zstdruby/libzstd/common/allocations.h
|
90
91
|
- ext/zstdruby/libzstd/common/bits.h
|
91
92
|
- ext/zstdruby/libzstd/common/bitstream.h
|
92
93
|
- ext/zstdruby/libzstd/common/compiler.h
|
@@ -156,6 +157,7 @@ files:
|
|
156
157
|
- ext/zstdruby/libzstd/zstd.h
|
157
158
|
- ext/zstdruby/libzstd/zstd_errors.h
|
158
159
|
- ext/zstdruby/main.c
|
160
|
+
- ext/zstdruby/skippable_frame.c
|
159
161
|
- ext/zstdruby/streaming_compress.c
|
160
162
|
- ext/zstdruby/streaming_compress.h
|
161
163
|
- ext/zstdruby/streaming_decompress.c
|