zstd-ruby 2.0.7 → 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/ext/zstdruby/zstdruby.c +36 -10
- 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: 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/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
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: 2.0.
|
|
4
|
+
version: 2.0.8
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- SpringMT
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-08-
|
|
11
|
+
date: 2026-08-09 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: bundler
|