zstd-ruby 2.0.6 → 2.0.8
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 +3 -3
- data/ext/zstdruby/skippable_frame.c +2 -2
- data/ext/zstdruby/zstdruby.c +36 -10
- data/lib/zstd-ruby/version.rb +1 -1
- data/zstd-ruby.gemspec +1 -1
- metadata +7 -4
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 2747a2ccb21d362d5523b5c986fd5f45e7bc2007a40710c303e14e69b66dd626
|
|
4
|
+
data.tar.gz: 9b396596f0877e8da07fedf4a90e5d54af41414262dd12754faff6b71e56b771
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 5cdeca9f57890066be8ad60fa7768b0920faac9bae169f6ca5069302a38e48a8c1e22d6b93a13abda415447dc7d750f38aef923527d055d04075d0d81d9a6556
|
|
7
|
+
data.tar.gz: a625f95323296768a68ccbc98fa4a24175d8a6d2643b3ef7ee4bf3b7cb1ceef2afc4ba4ba263b7bf2b7dbbc279ae89231f92d0d043aa4a1c6d96e8b8e03aa776
|
data/README.md
CHANGED
|
@@ -116,7 +116,7 @@ res << stream.finish
|
|
|
116
116
|
|
|
117
117
|
#### Streaming Compression with CDict of level 5
|
|
118
118
|
```ruby
|
|
119
|
-
cdict = Zstd::CDict.new(File.read('dictionary_file', 5)
|
|
119
|
+
cdict = Zstd::CDict.new(File.read('dictionary_file'), 5)
|
|
120
120
|
stream = Zstd::StreamingCompress.new(dict: cdict)
|
|
121
121
|
stream << "abc" << "def"
|
|
122
122
|
res = stream.flush
|
|
@@ -143,8 +143,8 @@ Zstd.decompress(compressed_using_dict, dict: File.read('dictionary_file'))
|
|
|
143
143
|
If you use the same dictionary repeatedly, you can speed up the setup by creating DDict in advance:
|
|
144
144
|
|
|
145
145
|
```ruby
|
|
146
|
-
ddict = Zstd::
|
|
147
|
-
data = Zstd.
|
|
146
|
+
ddict = Zstd::DDict.new(File.read('dictionary_file'))
|
|
147
|
+
data = Zstd.decompress(compressed_using_dict, dict: ddict)
|
|
148
148
|
```
|
|
149
149
|
|
|
150
150
|
#### Streaming Decompression
|
|
@@ -17,13 +17,12 @@ static VALUE rb_write_skippable_frame(int argc, VALUE *argv, VALUE self)
|
|
|
17
17
|
|
|
18
18
|
StringValue(input_value);
|
|
19
19
|
StringValue(skip_value);
|
|
20
|
-
char* input_data = RSTRING_PTR(input_value);
|
|
21
20
|
size_t input_size = RSTRING_LEN(input_value);
|
|
22
21
|
char* skip_data = RSTRING_PTR(skip_value);
|
|
23
22
|
size_t skip_size = RSTRING_LEN(skip_value);
|
|
24
23
|
|
|
25
24
|
size_t dst_size = input_size + ZSTD_SKIPPABLEHEADERSIZE + skip_size;
|
|
26
|
-
VALUE output = rb_str_new(
|
|
25
|
+
VALUE output = rb_str_new(NULL, dst_size);
|
|
27
26
|
char* output_data = RSTRING_PTR(output);
|
|
28
27
|
size_t output_size = ZSTD_writeSkippableFrame((void*)output_data, dst_size, (const void*)skip_data, skip_size, magic_variant);
|
|
29
28
|
if (ZSTD_isError(output_size)) {
|
|
@@ -36,6 +35,7 @@ static VALUE rb_write_skippable_frame(int argc, VALUE *argv, VALUE self)
|
|
|
36
35
|
|
|
37
36
|
static VALUE rb_read_skippable_frame(VALUE self, VALUE input_value)
|
|
38
37
|
{
|
|
38
|
+
StringValue(input_value);
|
|
39
39
|
char* input_data = RSTRING_PTR(input_value);
|
|
40
40
|
size_t input_size = RSTRING_LEN(input_value);
|
|
41
41
|
|
data/ext/zstdruby/zstdruby.c
CHANGED
|
@@ -40,7 +40,7 @@ static VALUE rb_compress(int argc, VALUE *argv, VALUE self)
|
|
|
40
40
|
return output;
|
|
41
41
|
}
|
|
42
42
|
|
|
43
|
-
static VALUE decode_one_frame(ZSTD_DCtx* dctx, const unsigned char* src, size_t size, VALUE kwargs) {
|
|
43
|
+
static VALUE decode_one_frame(ZSTD_DCtx* dctx, const unsigned char* src, size_t size, VALUE kwargs, size_t* consumed) {
|
|
44
44
|
VALUE out = rb_str_buf_new(0);
|
|
45
45
|
size_t cap = ZSTD_DStreamOutSize();
|
|
46
46
|
char *buf = ALLOC_N(char, cap);
|
|
@@ -64,11 +64,14 @@ static VALUE decode_one_frame(ZSTD_DCtx* dctx, const unsigned char* src, size_t
|
|
|
64
64
|
}
|
|
65
65
|
}
|
|
66
66
|
xfree(buf);
|
|
67
|
+
if (consumed) {
|
|
68
|
+
*consumed = in.pos;
|
|
69
|
+
}
|
|
67
70
|
return out;
|
|
68
71
|
}
|
|
69
72
|
|
|
70
73
|
static VALUE decompress_buffered(ZSTD_DCtx* dctx, const char* data, size_t len) {
|
|
71
|
-
return decode_one_frame(dctx, (const unsigned char*)data, len, Qnil);
|
|
74
|
+
return decode_one_frame(dctx, (const unsigned char*)data, len, Qnil, NULL);
|
|
72
75
|
}
|
|
73
76
|
|
|
74
77
|
static VALUE rb_decompress(int argc, VALUE *argv, VALUE self)
|
|
@@ -84,6 +87,9 @@ static VALUE rb_decompress(int argc, VALUE *argv, VALUE self)
|
|
|
84
87
|
const uint32_t ZSTD_MAGIC = 0xFD2FB528U;
|
|
85
88
|
const uint32_t SKIP_LO = 0x184D2A50U; /* ...5F */
|
|
86
89
|
|
|
90
|
+
VALUE result = Qnil;
|
|
91
|
+
ZSTD_DCtx *dctx = NULL;
|
|
92
|
+
|
|
87
93
|
while (off + 4 <= in_size) {
|
|
88
94
|
uint32_t magic = (uint32_t)in[off]
|
|
89
95
|
| ((uint32_t)in[off+1] << 8)
|
|
@@ -103,23 +109,43 @@ static VALUE rb_decompress(int argc, VALUE *argv, VALUE self)
|
|
|
103
109
|
}
|
|
104
110
|
|
|
105
111
|
if (magic == ZSTD_MAGIC) {
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
112
|
+
if (dctx == NULL) {
|
|
113
|
+
dctx = ZSTD_createDCtx();
|
|
114
|
+
if (!dctx) {
|
|
115
|
+
rb_raise(rb_eRuntimeError, "ZSTD_createDCtx failed");
|
|
116
|
+
}
|
|
109
117
|
}
|
|
110
118
|
|
|
111
|
-
|
|
119
|
+
size_t consumed = 0;
|
|
120
|
+
VALUE out = decode_one_frame(dctx, in + off, in_size - off, kwargs, &consumed);
|
|
121
|
+
if (result == Qnil) {
|
|
122
|
+
/* First frame becomes the accumulator, avoiding a copy of its
|
|
123
|
+
(potentially large) output in the common single-frame case. */
|
|
124
|
+
result = out;
|
|
125
|
+
} else {
|
|
126
|
+
rb_str_cat(result, RSTRING_PTR(out), RSTRING_LEN(out));
|
|
127
|
+
}
|
|
112
128
|
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
129
|
+
if (consumed == 0) {
|
|
130
|
+
/* Guard against a non-advancing frame to avoid an infinite loop. */
|
|
131
|
+
break;
|
|
132
|
+
}
|
|
133
|
+
off += consumed;
|
|
134
|
+
continue;
|
|
116
135
|
}
|
|
117
136
|
|
|
118
137
|
off += 1;
|
|
119
138
|
}
|
|
120
139
|
|
|
140
|
+
if (dctx != NULL) {
|
|
141
|
+
ZSTD_freeDCtx(dctx);
|
|
142
|
+
}
|
|
143
|
+
|
|
121
144
|
RB_GC_GUARD(input_value);
|
|
122
|
-
|
|
145
|
+
if (result == Qnil) {
|
|
146
|
+
rb_raise(rb_eRuntimeError, "not a zstd frame (magic not found)");
|
|
147
|
+
}
|
|
148
|
+
return result;
|
|
123
149
|
}
|
|
124
150
|
|
|
125
151
|
static void free_cdict(void *dict)
|
data/lib/zstd-ruby/version.rb
CHANGED
data/zstd-ruby.gemspec
CHANGED
|
@@ -12,7 +12,7 @@ Gem::Specification.new do |spec|
|
|
|
12
12
|
spec.summary = %q{Ruby binding for zstd(Zstandard - Fast real-time compression algorithm)}
|
|
13
13
|
spec.description = %q{Ruby binding for zstd(Zstandard - Fast real-time compression algorithm). See https://github.com/facebook/zstd}
|
|
14
14
|
spec.homepage = "https://github.com/SpringMT/zstd-ruby"
|
|
15
|
-
spec.license = "
|
|
15
|
+
spec.license = "BSD-3-Clause"
|
|
16
16
|
|
|
17
17
|
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
|
18
18
|
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
metadata
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
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.8
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- SpringMT
|
|
8
|
+
autorequire:
|
|
8
9
|
bindir: exe
|
|
9
10
|
cert_chain: []
|
|
10
|
-
date: 2026-
|
|
11
|
+
date: 2026-08-09 00:00:00.000000000 Z
|
|
11
12
|
dependencies:
|
|
12
13
|
- !ruby/object:Gem::Dependency
|
|
13
14
|
name: bundler
|
|
@@ -186,8 +187,9 @@ files:
|
|
|
186
187
|
- zstd-ruby.gemspec
|
|
187
188
|
homepage: https://github.com/SpringMT/zstd-ruby
|
|
188
189
|
licenses:
|
|
189
|
-
-
|
|
190
|
+
- BSD-3-Clause
|
|
190
191
|
metadata: {}
|
|
192
|
+
post_install_message:
|
|
191
193
|
rdoc_options: []
|
|
192
194
|
require_paths:
|
|
193
195
|
- lib
|
|
@@ -202,7 +204,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
202
204
|
- !ruby/object:Gem::Version
|
|
203
205
|
version: '0'
|
|
204
206
|
requirements: []
|
|
205
|
-
rubygems_version: 3.
|
|
207
|
+
rubygems_version: 3.4.19
|
|
208
|
+
signing_key:
|
|
206
209
|
specification_version: 4
|
|
207
210
|
summary: Ruby binding for zstd(Zstandard - Fast real-time compression algorithm)
|
|
208
211
|
test_files: []
|