zstd-ruby 1.5.2.0 → 1.5.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +2 -0
- data/README.md +55 -2
- data/Rakefile +8 -2
- data/ext/zstdruby/{zstdruby.h → common.h} +2 -0
- data/ext/zstdruby/main.c +14 -0
- data/ext/zstdruby/streaming_compress.c +185 -0
- data/ext/zstdruby/streaming_compress.h +5 -0
- data/ext/zstdruby/streaming_decompress.c +125 -0
- data/ext/zstdruby/zstdruby.c +4 -6
- data/lib/zstd-ruby/version.rb +1 -1
- data/zstd-ruby.gemspec +1 -1
- metadata +7 -36
- data/.github/dependabot.yml +0 -8
- data/.github/workflows/ruby.yml +0 -35
- data/ext/zstdruby/libzstd/.gitignore +0 -3
- data/ext/zstdruby/libzstd/BUCK +0 -232
- data/ext/zstdruby/libzstd/Makefile +0 -357
- data/ext/zstdruby/libzstd/README.md +0 -217
- data/ext/zstdruby/libzstd/deprecated/zbuff.h +0 -214
- data/ext/zstdruby/libzstd/deprecated/zbuff_common.c +0 -26
- data/ext/zstdruby/libzstd/deprecated/zbuff_compress.c +0 -167
- data/ext/zstdruby/libzstd/deprecated/zbuff_decompress.c +0 -75
- data/ext/zstdruby/libzstd/dll/example/Makefile +0 -48
- data/ext/zstdruby/libzstd/dll/example/README.md +0 -63
- data/ext/zstdruby/libzstd/dll/example/build_package.bat +0 -20
- data/ext/zstdruby/libzstd/dll/example/fullbench-dll.sln +0 -25
- data/ext/zstdruby/libzstd/dll/example/fullbench-dll.vcxproj +0 -181
- data/ext/zstdruby/libzstd/legacy/zstd_legacy.h +0 -415
- data/ext/zstdruby/libzstd/legacy/zstd_v01.c +0 -2158
- data/ext/zstdruby/libzstd/legacy/zstd_v01.h +0 -94
- data/ext/zstdruby/libzstd/legacy/zstd_v02.c +0 -3518
- data/ext/zstdruby/libzstd/legacy/zstd_v02.h +0 -93
- data/ext/zstdruby/libzstd/legacy/zstd_v03.c +0 -3160
- data/ext/zstdruby/libzstd/legacy/zstd_v03.h +0 -93
- data/ext/zstdruby/libzstd/legacy/zstd_v04.c +0 -3647
- data/ext/zstdruby/libzstd/legacy/zstd_v04.h +0 -142
- data/ext/zstdruby/libzstd/legacy/zstd_v05.c +0 -4050
- data/ext/zstdruby/libzstd/legacy/zstd_v05.h +0 -162
- data/ext/zstdruby/libzstd/legacy/zstd_v06.c +0 -4154
- data/ext/zstdruby/libzstd/legacy/zstd_v06.h +0 -172
- data/ext/zstdruby/libzstd/legacy/zstd_v07.c +0 -4541
- data/ext/zstdruby/libzstd/legacy/zstd_v07.h +0 -187
- data/ext/zstdruby/libzstd/libzstd.mk +0 -203
- data/ext/zstdruby/libzstd/libzstd.pc.in +0 -16
- data/ext/zstdruby/libzstd/module.modulemap +0 -25
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 70096397fcb0ba88b1332602dc743a979e6417bc07aa25270b2fa3e637922291
|
4
|
+
data.tar.gz: e3e2f2ddf2d2d01514e7128b01792e10d9b48cbc08f61a25e0cd9ddf3e91430e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fd02829550fef9d56add09f13c1bee7a5171830e6f7f08e728ef4140e922657b1c70df79e4dd4b56b1bf77cddedbcea4830405561d6cb027bbbce928ff5d7152
|
7
|
+
data.tar.gz: aa56ea5cbc0b9d6e6268691ad656d71f38afde239d9833f07c4ae02a6ab1e1ee2b81e92e5489db3e993774938e58d8fb884c8d882ba4126de15588164ceeff25
|
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -34,20 +34,73 @@ Or install it yourself as:
|
|
34
34
|
require 'zstd-ruby'
|
35
35
|
```
|
36
36
|
|
37
|
-
###
|
37
|
+
### Simple Compression
|
38
38
|
|
39
39
|
```ruby
|
40
40
|
compressed_data = Zstd.compress(data)
|
41
41
|
compressed_data = Zstd.compress(data, complession_level) # default compression_level is 0
|
42
42
|
```
|
43
43
|
|
44
|
+
### Streaming Compression
|
45
|
+
```
|
46
|
+
stream = Zstd::StreamingCompress.new
|
47
|
+
stream << "abc" << "def"
|
48
|
+
res = stream.flush
|
49
|
+
stream << "ghi"
|
50
|
+
res << stream.finish
|
51
|
+
```
|
52
|
+
|
53
|
+
or
|
54
|
+
|
55
|
+
```
|
56
|
+
stream = Zstd::StreamingCompress.new
|
57
|
+
res = stream.compress("abc")
|
58
|
+
res << stream.flush
|
59
|
+
res << stream.compress("def")
|
60
|
+
res << stream.finish
|
61
|
+
```
|
44
62
|
|
45
|
-
###
|
63
|
+
### Simple Decompression
|
46
64
|
|
47
65
|
```ruby
|
48
66
|
data = Zstd.decompress(compressed_data)
|
49
67
|
```
|
50
68
|
|
69
|
+
### Streaming Decompression
|
70
|
+
```
|
71
|
+
cstr = "" # Compressed data
|
72
|
+
stream = Zstd::StreamingDecompress.new
|
73
|
+
result = ''
|
74
|
+
result << stream.decompress(cstr[0, 10])
|
75
|
+
result << stream.decompress(cstr[10..-1])
|
76
|
+
```
|
77
|
+
|
78
|
+
|
79
|
+
## JRuby
|
80
|
+
This gem does not support JRuby.
|
81
|
+
|
82
|
+
Please consider using https://github.com/luben/zstd-jni.
|
83
|
+
|
84
|
+
Sample code is below.
|
85
|
+
|
86
|
+
```
|
87
|
+
require 'java'
|
88
|
+
require_relative './zstd-jni-1.5.2-3.jar'
|
89
|
+
|
90
|
+
str = "testtest"
|
91
|
+
compressed = com.github.luben.zstd.Zstd.compress(str.to_java_bytes)
|
92
|
+
puts com.github.luben.zstd.Zstd.decompress(compressed, str.length)
|
93
|
+
```
|
94
|
+
|
95
|
+
```
|
96
|
+
% ls
|
97
|
+
test.rb zstd-jni-1.5.2-3.jar
|
98
|
+
% ruby -v
|
99
|
+
jruby 9.3.2.0 (2.6.8) 2021-12-01 0b8223f905 OpenJDK 64-Bit Server VM 11.0.12+0 on 11.0.12+0 +jit [darwin-x86_64]
|
100
|
+
% ruby test.rb
|
101
|
+
testtest
|
102
|
+
```
|
103
|
+
|
51
104
|
## Development
|
52
105
|
|
53
106
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
data/Rakefile
CHANGED
@@ -17,6 +17,12 @@ task :default => [:clobber, :compile, :spec]
|
|
17
17
|
|
18
18
|
desc 'Sync zstd libs dirs to ext/zstdruby/libzstd'
|
19
19
|
task :zstd_update do
|
20
|
-
FileUtils.rm_r(
|
21
|
-
FileUtils.
|
20
|
+
FileUtils.rm_r("ext/zstdruby/libzstd")
|
21
|
+
FileUtils.mkdir_p("ext/zstdruby/libzstd")
|
22
|
+
["common", "compress", "decompress", "dictBuilder"].each do |dir|
|
23
|
+
FileUtils.cp_r("zstd/lib/#{dir}", "ext/zstdruby/libzstd/#{dir}")
|
24
|
+
end
|
25
|
+
FileUtils.cp_r('zstd/lib/zdict.h', 'ext/zstdruby/libzstd')
|
26
|
+
FileUtils.cp_r('zstd/lib/zstd.h', 'ext/zstdruby/libzstd')
|
27
|
+
FileUtils.cp_r('zstd/lib/zstd_errors.h', 'ext/zstdruby/libzstd')
|
22
28
|
end
|
data/ext/zstdruby/main.c
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#include <common.h>
|
2
|
+
VALUE rb_mZstd;
|
3
|
+
void zstd_ruby_init(void);
|
4
|
+
void zstd_ruby_streaming_compress_init(void);
|
5
|
+
void zstd_ruby_streaming_decompress_init(void);
|
6
|
+
|
7
|
+
void
|
8
|
+
Init_zstdruby(void)
|
9
|
+
{
|
10
|
+
rb_mZstd = rb_define_module("Zstd");
|
11
|
+
zstd_ruby_init();
|
12
|
+
zstd_ruby_streaming_compress_init();
|
13
|
+
zstd_ruby_streaming_decompress_init();
|
14
|
+
}
|
@@ -0,0 +1,185 @@
|
|
1
|
+
#include <common.h>
|
2
|
+
#include <streaming_compress.h>
|
3
|
+
|
4
|
+
struct streaming_compress_t {
|
5
|
+
ZSTD_CCtx* ctx;
|
6
|
+
VALUE buf;
|
7
|
+
size_t buf_size;
|
8
|
+
};
|
9
|
+
|
10
|
+
static void
|
11
|
+
streaming_compress_mark(void *p)
|
12
|
+
{
|
13
|
+
struct streaming_compress_t *sc = p;
|
14
|
+
// rb_gc_mark((VALUE)sc->ctx);
|
15
|
+
rb_gc_mark(sc->buf);
|
16
|
+
rb_gc_mark(sc->buf_size);
|
17
|
+
}
|
18
|
+
|
19
|
+
static void
|
20
|
+
streaming_compress_free(void *p)
|
21
|
+
{
|
22
|
+
struct streaming_compress_t *sc = p;
|
23
|
+
ZSTD_CCtx* ctx = sc->ctx;
|
24
|
+
if (ctx != NULL) {
|
25
|
+
ZSTD_freeCCtx(ctx);
|
26
|
+
}
|
27
|
+
xfree(sc);
|
28
|
+
}
|
29
|
+
|
30
|
+
static size_t
|
31
|
+
streaming_compress_memsize(const void *p)
|
32
|
+
{
|
33
|
+
return sizeof(struct streaming_compress_t);
|
34
|
+
}
|
35
|
+
|
36
|
+
static const rb_data_type_t streaming_compress_type = {
|
37
|
+
"streaming_compress",
|
38
|
+
{ streaming_compress_mark, streaming_compress_free, streaming_compress_memsize, },
|
39
|
+
0, 0, RUBY_TYPED_FREE_IMMEDIATELY
|
40
|
+
};
|
41
|
+
|
42
|
+
static VALUE
|
43
|
+
rb_streaming_compress_allocate(VALUE klass)
|
44
|
+
{
|
45
|
+
struct streaming_compress_t* sc;
|
46
|
+
VALUE obj = TypedData_Make_Struct(klass, struct streaming_compress_t, &streaming_compress_type, sc);
|
47
|
+
sc->ctx = NULL;
|
48
|
+
sc->buf = Qnil;
|
49
|
+
sc->buf_size = 0;
|
50
|
+
return obj;
|
51
|
+
}
|
52
|
+
|
53
|
+
static VALUE
|
54
|
+
rb_streaming_compress_initialize(int argc, VALUE *argv, VALUE obj)
|
55
|
+
{
|
56
|
+
VALUE compression_level_value;
|
57
|
+
rb_scan_args(argc, argv, "01", &compression_level_value);
|
58
|
+
|
59
|
+
int compression_level;
|
60
|
+
if (NIL_P(compression_level_value)) {
|
61
|
+
compression_level = 0; // The default. See ZSTD_CLEVEL_DEFAULT in zstd_compress.c
|
62
|
+
} else {
|
63
|
+
compression_level = NUM2INT(compression_level_value);
|
64
|
+
}
|
65
|
+
|
66
|
+
struct streaming_compress_t* sc;
|
67
|
+
TypedData_Get_Struct(obj, struct streaming_compress_t, &streaming_compress_type, sc);
|
68
|
+
size_t const buffOutSize = ZSTD_CStreamOutSize();
|
69
|
+
|
70
|
+
ZSTD_CCtx* ctx = ZSTD_createCCtx();
|
71
|
+
if (ctx == NULL) {
|
72
|
+
rb_raise(rb_eRuntimeError, "%s", "ZSTD_createCCtx error");
|
73
|
+
}
|
74
|
+
ZSTD_CCtx_setParameter(ctx, ZSTD_c_compressionLevel, compression_level);
|
75
|
+
sc->ctx = ctx;
|
76
|
+
sc->buf = rb_str_new(NULL, buffOutSize);
|
77
|
+
sc->buf_size = buffOutSize;
|
78
|
+
|
79
|
+
return obj;
|
80
|
+
}
|
81
|
+
|
82
|
+
#define FIXNUMARG(val, ifnil) \
|
83
|
+
(NIL_P((val)) ? (ifnil) \
|
84
|
+
: (FIX2INT((val))))
|
85
|
+
#define ARG_CONTINUE(val) FIXNUMARG((val), ZSTD_e_continue)
|
86
|
+
|
87
|
+
static VALUE
|
88
|
+
no_compress(struct streaming_compress_t* sc, ZSTD_EndDirective endOp)
|
89
|
+
{
|
90
|
+
ZSTD_inBuffer input = { NULL, 0, 0 };
|
91
|
+
const char* output_data = RSTRING_PTR(sc->buf);
|
92
|
+
VALUE result = rb_str_new(0, 0);
|
93
|
+
size_t ret;
|
94
|
+
do {
|
95
|
+
ZSTD_outBuffer output = { (void*)output_data, sc->buf_size, 0 };
|
96
|
+
|
97
|
+
size_t const ret = ZSTD_compressStream2(sc->ctx, &output, &input, endOp);
|
98
|
+
if (ZSTD_isError(ret)) {
|
99
|
+
rb_raise(rb_eRuntimeError, "flush error error code: %s", ZSTD_getErrorName(ret));
|
100
|
+
}
|
101
|
+
rb_str_cat(result, output.dst, output.pos);
|
102
|
+
} while (ret > 0);
|
103
|
+
return result;
|
104
|
+
}
|
105
|
+
|
106
|
+
static VALUE
|
107
|
+
rb_streaming_compress_compress(VALUE obj, VALUE src)
|
108
|
+
{
|
109
|
+
StringValue(src);
|
110
|
+
const char* input_data = RSTRING_PTR(src);
|
111
|
+
size_t input_size = RSTRING_LEN(src);
|
112
|
+
ZSTD_inBuffer input = { input_data, input_size, 0 };
|
113
|
+
|
114
|
+
struct streaming_compress_t* sc;
|
115
|
+
TypedData_Get_Struct(obj, struct streaming_compress_t, &streaming_compress_type, sc);
|
116
|
+
const char* output_data = RSTRING_PTR(sc->buf);
|
117
|
+
VALUE result = rb_str_new(0, 0);
|
118
|
+
while (input.pos < input.size) {
|
119
|
+
ZSTD_outBuffer output = { (void*)output_data, sc->buf_size, 0 };
|
120
|
+
size_t const ret = ZSTD_compressStream2(sc->ctx, &output, &input, ZSTD_e_continue);
|
121
|
+
if (ZSTD_isError(ret)) {
|
122
|
+
rb_raise(rb_eRuntimeError, "compress error error code: %s", ZSTD_getErrorName(ret));
|
123
|
+
}
|
124
|
+
rb_str_cat(result, output.dst, output.pos);
|
125
|
+
}
|
126
|
+
return result;
|
127
|
+
}
|
128
|
+
|
129
|
+
static VALUE
|
130
|
+
rb_streaming_compress_addstr(VALUE obj, VALUE src)
|
131
|
+
{
|
132
|
+
StringValue(src);
|
133
|
+
const char* input_data = RSTRING_PTR(src);
|
134
|
+
size_t input_size = RSTRING_LEN(src);
|
135
|
+
ZSTD_inBuffer input = { input_data, input_size, 0 };
|
136
|
+
|
137
|
+
struct streaming_compress_t* sc;
|
138
|
+
TypedData_Get_Struct(obj, struct streaming_compress_t, &streaming_compress_type, sc);
|
139
|
+
const char* output_data = RSTRING_PTR(sc->buf);
|
140
|
+
|
141
|
+
while (input.pos < input.size) {
|
142
|
+
ZSTD_outBuffer output = { (void*)output_data, sc->buf_size, 0 };
|
143
|
+
size_t const result = ZSTD_compressStream2(sc->ctx, &output, &input, ZSTD_e_continue);
|
144
|
+
if (ZSTD_isError(result)) {
|
145
|
+
rb_raise(rb_eRuntimeError, "compress error error code: %s", ZSTD_getErrorName(result));
|
146
|
+
}
|
147
|
+
}
|
148
|
+
return obj;
|
149
|
+
}
|
150
|
+
|
151
|
+
static VALUE
|
152
|
+
rb_streaming_compress_flush(VALUE obj)
|
153
|
+
{
|
154
|
+
struct streaming_compress_t* sc;
|
155
|
+
TypedData_Get_Struct(obj, struct streaming_compress_t, &streaming_compress_type, sc);
|
156
|
+
VALUE result = no_compress(sc, ZSTD_e_flush);
|
157
|
+
return result;
|
158
|
+
}
|
159
|
+
|
160
|
+
static VALUE
|
161
|
+
rb_streaming_compress_finish(VALUE obj)
|
162
|
+
{
|
163
|
+
struct streaming_compress_t* sc;
|
164
|
+
TypedData_Get_Struct(obj, struct streaming_compress_t, &streaming_compress_type, sc);
|
165
|
+
VALUE result = no_compress(sc, ZSTD_e_end);
|
166
|
+
return result;
|
167
|
+
}
|
168
|
+
|
169
|
+
extern VALUE rb_mZstd, cStreamingCompress;
|
170
|
+
void
|
171
|
+
zstd_ruby_streaming_compress_init(void)
|
172
|
+
{
|
173
|
+
VALUE cStreamingCompress = rb_define_class_under(rb_mZstd, "StreamingCompress", rb_cObject);
|
174
|
+
rb_define_alloc_func(cStreamingCompress, rb_streaming_compress_allocate);
|
175
|
+
rb_define_method(cStreamingCompress, "initialize", rb_streaming_compress_initialize, -1);
|
176
|
+
rb_define_method(cStreamingCompress, "compress", rb_streaming_compress_compress, 1);
|
177
|
+
rb_define_method(cStreamingCompress, "<<", rb_streaming_compress_addstr, 1);
|
178
|
+
rb_define_method(cStreamingCompress, "flush", rb_streaming_compress_flush, 0);
|
179
|
+
rb_define_method(cStreamingCompress, "finish", rb_streaming_compress_finish, 0);
|
180
|
+
|
181
|
+
rb_define_const(cStreamingCompress, "CONTINUE", INT2FIX(ZSTD_e_continue));
|
182
|
+
rb_define_const(cStreamingCompress, "FLUSH", INT2FIX(ZSTD_e_flush));
|
183
|
+
rb_define_const(cStreamingCompress, "END", INT2FIX(ZSTD_e_end));
|
184
|
+
}
|
185
|
+
|
@@ -0,0 +1,125 @@
|
|
1
|
+
#include <common.h>
|
2
|
+
|
3
|
+
struct streaming_decompress_t {
|
4
|
+
ZSTD_DCtx* ctx;
|
5
|
+
VALUE buf;
|
6
|
+
size_t buf_size;
|
7
|
+
};
|
8
|
+
|
9
|
+
static void
|
10
|
+
streaming_decompress_mark(void *p)
|
11
|
+
{
|
12
|
+
struct streaming_decompress_t *sd = p;
|
13
|
+
// rb_gc_mark((VALUE)sd->ctx);
|
14
|
+
rb_gc_mark(sd->buf);
|
15
|
+
rb_gc_mark(sd->buf_size);
|
16
|
+
}
|
17
|
+
|
18
|
+
static void
|
19
|
+
streaming_decompress_free(void *p)
|
20
|
+
{
|
21
|
+
struct streaming_decompress_t *sd = p;
|
22
|
+
ZSTD_DCtx* ctx = sd->ctx;
|
23
|
+
if (ctx != NULL) {
|
24
|
+
ZSTD_freeDCtx(ctx);
|
25
|
+
}
|
26
|
+
xfree(sd);
|
27
|
+
}
|
28
|
+
|
29
|
+
static size_t
|
30
|
+
streaming_decompress_memsize(const void *p)
|
31
|
+
{
|
32
|
+
return sizeof(struct streaming_decompress_t);
|
33
|
+
}
|
34
|
+
|
35
|
+
static const rb_data_type_t streaming_decompress_type = {
|
36
|
+
"streaming_decompress",
|
37
|
+
{ streaming_decompress_mark, streaming_decompress_free, streaming_decompress_memsize, },
|
38
|
+
0, 0, RUBY_TYPED_FREE_IMMEDIATELY
|
39
|
+
};
|
40
|
+
|
41
|
+
static VALUE
|
42
|
+
rb_streaming_decompress_allocate(VALUE klass)
|
43
|
+
{
|
44
|
+
struct streaming_decompress_t* sd;
|
45
|
+
VALUE obj = TypedData_Make_Struct(klass, struct streaming_decompress_t, &streaming_decompress_type, sd);
|
46
|
+
sd->ctx = NULL;
|
47
|
+
sd->buf = Qnil;
|
48
|
+
sd->buf_size = 0;
|
49
|
+
return obj;
|
50
|
+
}
|
51
|
+
|
52
|
+
static VALUE
|
53
|
+
rb_streaming_decompress_initialize(VALUE obj)
|
54
|
+
{
|
55
|
+
struct streaming_decompress_t* sd;
|
56
|
+
TypedData_Get_Struct(obj, struct streaming_decompress_t, &streaming_decompress_type, sd);
|
57
|
+
size_t const buffOutSize = ZSTD_DStreamOutSize();
|
58
|
+
|
59
|
+
ZSTD_DCtx* ctx = ZSTD_createDCtx();
|
60
|
+
if (ctx == NULL) {
|
61
|
+
rb_raise(rb_eRuntimeError, "%s", "ZSTD_createDCtx error");
|
62
|
+
}
|
63
|
+
sd->ctx = ctx;
|
64
|
+
sd->buf = rb_str_new(NULL, buffOutSize);
|
65
|
+
sd->buf_size = buffOutSize;
|
66
|
+
|
67
|
+
return obj;
|
68
|
+
}
|
69
|
+
|
70
|
+
static VALUE
|
71
|
+
rb_streaming_decompress_decompress(VALUE obj, VALUE src)
|
72
|
+
{
|
73
|
+
StringValue(src);
|
74
|
+
const char* input_data = RSTRING_PTR(src);
|
75
|
+
size_t input_size = RSTRING_LEN(src);
|
76
|
+
ZSTD_inBuffer input = { input_data, input_size, 0 };
|
77
|
+
|
78
|
+
struct streaming_decompress_t* sd;
|
79
|
+
TypedData_Get_Struct(obj, struct streaming_decompress_t, &streaming_decompress_type, sd);
|
80
|
+
const char* output_data = RSTRING_PTR(sd->buf);
|
81
|
+
VALUE result = rb_str_new(0, 0);
|
82
|
+
while (input.pos < input.size) {
|
83
|
+
ZSTD_outBuffer output = { (void*)output_data, sd->buf_size, 0 };
|
84
|
+
size_t const ret = ZSTD_decompressStream(sd->ctx, &output, &input);
|
85
|
+
if (ZSTD_isError(ret)) {
|
86
|
+
rb_raise(rb_eRuntimeError, "compress error error code: %s", ZSTD_getErrorName(ret));
|
87
|
+
}
|
88
|
+
rb_str_cat(result, output.dst, output.pos);
|
89
|
+
}
|
90
|
+
return result;
|
91
|
+
}
|
92
|
+
|
93
|
+
static VALUE
|
94
|
+
rb_streaming_decompress_addstr(VALUE obj, VALUE src)
|
95
|
+
{
|
96
|
+
StringValue(src);
|
97
|
+
const char* input_data = RSTRING_PTR(src);
|
98
|
+
size_t input_size = RSTRING_LEN(src);
|
99
|
+
ZSTD_inBuffer input = { input_data, input_size, 0 };
|
100
|
+
|
101
|
+
struct streaming_decompress_t* sd;
|
102
|
+
TypedData_Get_Struct(obj, struct streaming_decompress_t, &streaming_decompress_type, sd);
|
103
|
+
const char* output_data = RSTRING_PTR(sd->buf);
|
104
|
+
|
105
|
+
while (input.pos < input.size) {
|
106
|
+
ZSTD_outBuffer output = { (void*)output_data, sd->buf_size, 0 };
|
107
|
+
size_t const result = ZSTD_decompressStream(sd->ctx, &output, &input);
|
108
|
+
if (ZSTD_isError(result)) {
|
109
|
+
rb_raise(rb_eRuntimeError, "compress error error code: %s", ZSTD_getErrorName(result));
|
110
|
+
}
|
111
|
+
}
|
112
|
+
return obj;
|
113
|
+
}
|
114
|
+
|
115
|
+
extern VALUE rb_mZstd, cStreamingDecompress;
|
116
|
+
void
|
117
|
+
zstd_ruby_streaming_decompress_init(void)
|
118
|
+
{
|
119
|
+
VALUE cStreamingDecompress = rb_define_class_under(rb_mZstd, "StreamingDecompress", rb_cObject);
|
120
|
+
rb_define_alloc_func(cStreamingDecompress, rb_streaming_decompress_allocate);
|
121
|
+
rb_define_method(cStreamingDecompress, "initialize", rb_streaming_decompress_initialize, 0);
|
122
|
+
rb_define_method(cStreamingDecompress, "decompress", rb_streaming_decompress_decompress, 1);
|
123
|
+
rb_define_method(cStreamingDecompress, "<<", rb_streaming_decompress_addstr, 1);
|
124
|
+
}
|
125
|
+
|
data/ext/zstdruby/zstdruby.c
CHANGED
@@ -1,5 +1,6 @@
|
|
1
|
-
#include
|
2
|
-
|
1
|
+
#include <common.h>
|
2
|
+
|
3
|
+
extern VALUE rb_mZstd;
|
3
4
|
|
4
5
|
static VALUE zstdVersion(VALUE self)
|
5
6
|
{
|
@@ -104,12 +105,9 @@ static VALUE decompress(VALUE self, VALUE input)
|
|
104
105
|
return output;
|
105
106
|
}
|
106
107
|
|
107
|
-
VALUE rb_mZstd;
|
108
|
-
|
109
108
|
void
|
110
|
-
|
109
|
+
zstd_ruby_init(void)
|
111
110
|
{
|
112
|
-
rb_mZstd = rb_define_module("Zstd");
|
113
111
|
rb_define_module_function(rb_mZstd, "zstd_version", zstdVersion, 0);
|
114
112
|
rb_define_module_function(rb_mZstd, "compress", compress, -1);
|
115
113
|
rb_define_module_function(rb_mZstd, "decompress", decompress, 1);
|
data/lib/zstd-ruby/version.rb
CHANGED
data/zstd-ruby.gemspec
CHANGED
@@ -24,7 +24,7 @@ Gem::Specification.new do |spec|
|
|
24
24
|
#end
|
25
25
|
|
26
26
|
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
27
|
-
f.match(%r{^(test|spec|features|benchmarks|zstd)/})
|
27
|
+
f.match(%r{^(test|spec|features|benchmarks|zstd|.github)/})
|
28
28
|
end
|
29
29
|
spec.bindir = "exe"
|
30
30
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
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.2.
|
4
|
+
version: 1.5.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- SpringMT
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-06-
|
11
|
+
date: 2022-06-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -75,8 +75,6 @@ extensions:
|
|
75
75
|
- ext/zstdruby/extconf.rb
|
76
76
|
extra_rdoc_files: []
|
77
77
|
files:
|
78
|
-
- ".github/dependabot.yml"
|
79
|
-
- ".github/workflows/ruby.yml"
|
80
78
|
- ".gitignore"
|
81
79
|
- ".gitmodules"
|
82
80
|
- ".rspec"
|
@@ -87,11 +85,8 @@ files:
|
|
87
85
|
- Rakefile
|
88
86
|
- bin/console
|
89
87
|
- bin/setup
|
88
|
+
- ext/zstdruby/common.h
|
90
89
|
- ext/zstdruby/extconf.rb
|
91
|
-
- ext/zstdruby/libzstd/.gitignore
|
92
|
-
- ext/zstdruby/libzstd/BUCK
|
93
|
-
- ext/zstdruby/libzstd/Makefile
|
94
|
-
- ext/zstdruby/libzstd/README.md
|
95
90
|
- ext/zstdruby/libzstd/common/bitstream.h
|
96
91
|
- ext/zstdruby/libzstd/common/compiler.h
|
97
92
|
- ext/zstdruby/libzstd/common/cpu.h
|
@@ -150,44 +145,20 @@ files:
|
|
150
145
|
- ext/zstdruby/libzstd/decompress/zstd_decompress_block.c
|
151
146
|
- ext/zstdruby/libzstd/decompress/zstd_decompress_block.h
|
152
147
|
- ext/zstdruby/libzstd/decompress/zstd_decompress_internal.h
|
153
|
-
- ext/zstdruby/libzstd/deprecated/zbuff.h
|
154
|
-
- ext/zstdruby/libzstd/deprecated/zbuff_common.c
|
155
|
-
- ext/zstdruby/libzstd/deprecated/zbuff_compress.c
|
156
|
-
- ext/zstdruby/libzstd/deprecated/zbuff_decompress.c
|
157
148
|
- ext/zstdruby/libzstd/dictBuilder/cover.c
|
158
149
|
- ext/zstdruby/libzstd/dictBuilder/cover.h
|
159
150
|
- ext/zstdruby/libzstd/dictBuilder/divsufsort.c
|
160
151
|
- ext/zstdruby/libzstd/dictBuilder/divsufsort.h
|
161
152
|
- ext/zstdruby/libzstd/dictBuilder/fastcover.c
|
162
153
|
- ext/zstdruby/libzstd/dictBuilder/zdict.c
|
163
|
-
- ext/zstdruby/libzstd/dll/example/Makefile
|
164
|
-
- ext/zstdruby/libzstd/dll/example/README.md
|
165
|
-
- ext/zstdruby/libzstd/dll/example/build_package.bat
|
166
|
-
- ext/zstdruby/libzstd/dll/example/fullbench-dll.sln
|
167
|
-
- ext/zstdruby/libzstd/dll/example/fullbench-dll.vcxproj
|
168
|
-
- ext/zstdruby/libzstd/legacy/zstd_legacy.h
|
169
|
-
- ext/zstdruby/libzstd/legacy/zstd_v01.c
|
170
|
-
- ext/zstdruby/libzstd/legacy/zstd_v01.h
|
171
|
-
- ext/zstdruby/libzstd/legacy/zstd_v02.c
|
172
|
-
- ext/zstdruby/libzstd/legacy/zstd_v02.h
|
173
|
-
- ext/zstdruby/libzstd/legacy/zstd_v03.c
|
174
|
-
- ext/zstdruby/libzstd/legacy/zstd_v03.h
|
175
|
-
- ext/zstdruby/libzstd/legacy/zstd_v04.c
|
176
|
-
- ext/zstdruby/libzstd/legacy/zstd_v04.h
|
177
|
-
- ext/zstdruby/libzstd/legacy/zstd_v05.c
|
178
|
-
- ext/zstdruby/libzstd/legacy/zstd_v05.h
|
179
|
-
- ext/zstdruby/libzstd/legacy/zstd_v06.c
|
180
|
-
- ext/zstdruby/libzstd/legacy/zstd_v06.h
|
181
|
-
- ext/zstdruby/libzstd/legacy/zstd_v07.c
|
182
|
-
- ext/zstdruby/libzstd/legacy/zstd_v07.h
|
183
|
-
- ext/zstdruby/libzstd/libzstd.mk
|
184
|
-
- ext/zstdruby/libzstd/libzstd.pc.in
|
185
|
-
- ext/zstdruby/libzstd/module.modulemap
|
186
154
|
- ext/zstdruby/libzstd/zdict.h
|
187
155
|
- ext/zstdruby/libzstd/zstd.h
|
188
156
|
- ext/zstdruby/libzstd/zstd_errors.h
|
157
|
+
- ext/zstdruby/main.c
|
158
|
+
- ext/zstdruby/streaming_compress.c
|
159
|
+
- ext/zstdruby/streaming_compress.h
|
160
|
+
- ext/zstdruby/streaming_decompress.c
|
189
161
|
- ext/zstdruby/zstdruby.c
|
190
|
-
- ext/zstdruby/zstdruby.h
|
191
162
|
- lib/zstd-ruby.rb
|
192
163
|
- lib/zstd-ruby/version.rb
|
193
164
|
- zstd-ruby.gemspec
|
data/.github/dependabot.yml
DELETED
data/.github/workflows/ruby.yml
DELETED
@@ -1,35 +0,0 @@
|
|
1
|
-
# This workflow uses actions that are not certified by GitHub.
|
2
|
-
# They are provided by a third-party and are governed by
|
3
|
-
# separate terms of service, privacy policy, and support
|
4
|
-
# documentation.
|
5
|
-
# This workflow will download a prebuilt Ruby version, install dependencies and run tests with Rake
|
6
|
-
# For more information see: https://github.com/marketplace/actions/setup-ruby-jruby-and-truffleruby
|
7
|
-
|
8
|
-
name: Ruby
|
9
|
-
|
10
|
-
on: [push, pull_request]
|
11
|
-
|
12
|
-
jobs:
|
13
|
-
test:
|
14
|
-
|
15
|
-
runs-on: ubuntu-latest
|
16
|
-
strategy:
|
17
|
-
matrix:
|
18
|
-
ruby-version: ['2.6', '2.7', '3.0', '3.1']
|
19
|
-
|
20
|
-
steps:
|
21
|
-
- uses: actions/checkout@v2
|
22
|
-
- name: Set up Ruby
|
23
|
-
# To automatically get bug fixes and new Ruby versions for ruby/setup-ruby,
|
24
|
-
# change this to (see https://github.com/ruby/setup-ruby#versioning):
|
25
|
-
# uses: ruby/setup-ruby@v1
|
26
|
-
uses: ruby/setup-ruby@168d6a54b412713c0ed60998a78093a270ca8d84
|
27
|
-
with:
|
28
|
-
ruby-version: ${{ matrix.ruby-version }}
|
29
|
-
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
|
30
|
-
- name: Install dependencies
|
31
|
-
run: bundle install
|
32
|
-
- name: Compile
|
33
|
-
run: bundle exec rake compile
|
34
|
-
- name: Run tests
|
35
|
-
run: bundle exec rspec
|