ruby-zstds 1.0.2 → 1.0.3
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 +14 -12
- data/ext/zstds_ext/common.h +3 -0
- data/ext/zstds_ext/dictionary.c +1 -4
- data/ext/zstds_ext/error.c +0 -1
- data/ext/zstds_ext/io.c +37 -40
- data/ext/zstds_ext/main.c +0 -1
- data/ext/zstds_ext/option.c +0 -4
- data/ext/zstds_ext/option.h +3 -5
- data/ext/zstds_ext/stream/compressor.c +6 -9
- data/ext/zstds_ext/stream/compressor.h +6 -7
- data/ext/zstds_ext/stream/decompressor.c +6 -9
- data/ext/zstds_ext/stream/decompressor.h +6 -7
- data/ext/zstds_ext/string.c +2 -5
- data/lib/zstds/stream/abstract.rb +8 -6
- data/lib/zstds/stream/reader.rb +1 -1
- data/lib/zstds/stream/writer.rb +1 -1
- data/lib/zstds/stream/writer_helpers.rb +3 -3
- data/lib/zstds/validation.rb +14 -1
- data/lib/zstds/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e2279b518a90a526dd82247626f5969d01f6786de10b91802c5b6b7f3391ac26
|
4
|
+
data.tar.gz: 854b6e8d08c7cc2fa464e3acc25cf45ea6ff204809b5b2cb08cea94217e34b1f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 68781c24292733752c2e59022d71c31d15d73e73f7b5297374e720fc88e06100e1513772304b7591f16652bfef38b4991b9128949355fd0746bbae9d671eff67
|
7
|
+
data.tar.gz: dab52302d4ce11b2392d7578fd824c4e4b725c3a7d7c853454d05b7291eeb7a93b024fce8c8d475ea965202bb7795db9a3d59764a5aea012fea49d712a59ae4e
|
data/README.md
CHANGED
@@ -306,7 +306,7 @@ File maintains both source and destination buffers, it accepts both `source_buff
|
|
306
306
|
|
307
307
|
## Stream::Writer
|
308
308
|
|
309
|
-
Its behaviour is similar to builtin [`Zlib::GzipWriter`](https://ruby-doc.org/stdlib-2.
|
309
|
+
Its behaviour is similar to builtin [`Zlib::GzipWriter`](https://ruby-doc.org/stdlib-2.7.0/libdoc/zlib/rdoc/Zlib/GzipWriter.html).
|
310
310
|
|
311
311
|
Writer maintains destination buffer only, so it accepts `destination_buffer_length` option only.
|
312
312
|
|
@@ -344,7 +344,7 @@ Set another encodings, `nil` is just for compatibility with `IO`.
|
|
344
344
|
#tell
|
345
345
|
```
|
346
346
|
|
347
|
-
See [`IO`](https://ruby-doc.org/core-2.
|
347
|
+
See [`IO`](https://ruby-doc.org/core-2.7.0/IO.html) docs.
|
348
348
|
|
349
349
|
```
|
350
350
|
#write(*objects)
|
@@ -354,7 +354,7 @@ See [`IO`](https://ruby-doc.org/core-2.6.1/IO.html) docs.
|
|
354
354
|
#closed?
|
355
355
|
```
|
356
356
|
|
357
|
-
See [`Zlib::GzipWriter`](https://ruby-doc.org/stdlib-2.
|
357
|
+
See [`Zlib::GzipWriter`](https://ruby-doc.org/stdlib-2.7.0/libdoc/zlib/rdoc/Zlib/GzipWriter.html) docs.
|
358
358
|
|
359
359
|
```
|
360
360
|
#write_nonblock(object, *options)
|
@@ -376,11 +376,11 @@ Behaviour is the same as `IO#write_nonblock` method.
|
|
376
376
|
#puts(*objects)
|
377
377
|
```
|
378
378
|
|
379
|
-
Typical helpers, see [`Zlib::GzipWriter`](https://ruby-doc.org/stdlib-2.
|
379
|
+
Typical helpers, see [`Zlib::GzipWriter`](https://ruby-doc.org/stdlib-2.7.0/libdoc/zlib/rdoc/Zlib/GzipWriter.html) docs.
|
380
380
|
|
381
381
|
## Stream::Reader
|
382
382
|
|
383
|
-
Its behaviour is similar to builtin [`Zlib::GzipReader`](https://ruby-doc.org/stdlib-2.
|
383
|
+
Its behaviour is similar to builtin [`Zlib::GzipReader`](https://ruby-doc.org/stdlib-2.7.0/libdoc/zlib/rdoc/Zlib/GzipReader.html).
|
384
384
|
|
385
385
|
Reader maintains both source and destination buffers, it accepts both `source_buffer_length` and `destination_buffer_length` options.
|
386
386
|
|
@@ -415,7 +415,7 @@ Set another encodings.
|
|
415
415
|
#tell
|
416
416
|
```
|
417
417
|
|
418
|
-
See [`IO`](https://ruby-doc.org/core-2.
|
418
|
+
See [`IO`](https://ruby-doc.org/core-2.7.0/IO.html) docs.
|
419
419
|
|
420
420
|
```
|
421
421
|
#read(bytes_to_read = nil, out_buffer = nil)
|
@@ -425,14 +425,14 @@ See [`IO`](https://ruby-doc.org/core-2.6.1/IO.html) docs.
|
|
425
425
|
#closed?
|
426
426
|
```
|
427
427
|
|
428
|
-
See [`Zlib::GzipReader`](https://ruby-doc.org/stdlib-2.
|
428
|
+
See [`Zlib::GzipReader`](https://ruby-doc.org/stdlib-2.7.0/libdoc/zlib/rdoc/Zlib/GzipReader.html) docs.
|
429
429
|
|
430
430
|
```
|
431
431
|
#readpartial(bytes_to_read = nil, out_buffer = nil)
|
432
432
|
#read_nonblock(bytes_to_read, out_buffer = nil, *options)
|
433
433
|
```
|
434
434
|
|
435
|
-
See [`IO`](https://ruby-doc.org/core-2.
|
435
|
+
See [`IO`](https://ruby-doc.org/core-2.7.0/IO.html) docs.
|
436
436
|
|
437
437
|
```
|
438
438
|
#getbyte
|
@@ -455,7 +455,7 @@ See [`IO`](https://ruby-doc.org/core-2.6.1/IO.html) docs.
|
|
455
455
|
#ungetline(line)
|
456
456
|
```
|
457
457
|
|
458
|
-
Typical helpers, see [`Zlib::GzipReader`](https://ruby-doc.org/stdlib-2.
|
458
|
+
Typical helpers, see [`Zlib::GzipReader`](https://ruby-doc.org/stdlib-2.7.0/libdoc/zlib/rdoc/Zlib/GzipReader.html) docs.
|
459
459
|
|
460
460
|
## Dictionary
|
461
461
|
|
@@ -489,9 +489,11 @@ Read dictionary id from buffer.
|
|
489
489
|
|
490
490
|
## CI
|
491
491
|
|
492
|
-
|
493
|
-
|
494
|
-
|
492
|
+
See universal test script [scripts/ci_test.sh](scripts/ci_test.sh) for CI.
|
493
|
+
Please visit [scripts/test-images](scripts/test-images).
|
494
|
+
You can run this test script using many native and cross images.
|
495
|
+
|
496
|
+
Cirrus CI uses `x86_64-pc-linux-gnu` image, Circle CI - `x86_64-gentoo-linux-musl` image.
|
495
497
|
|
496
498
|
## License
|
497
499
|
|
data/ext/zstds_ext/common.h
CHANGED
data/ext/zstds_ext/dictionary.c
CHANGED
@@ -3,14 +3,11 @@
|
|
3
3
|
|
4
4
|
#include "zstds_ext/dictionary.h"
|
5
5
|
|
6
|
-
#include <stdint.h>
|
7
|
-
#include <stdlib.h>
|
8
6
|
#include <string.h>
|
9
7
|
#include <zdict.h>
|
10
8
|
|
11
9
|
#include "ruby.h"
|
12
10
|
#include "zstds_ext/buffer.h"
|
13
|
-
#include "zstds_ext/common.h"
|
14
11
|
#include "zstds_ext/error.h"
|
15
12
|
#include "zstds_ext/macro.h"
|
16
13
|
#include "zstds_ext/option.h"
|
@@ -54,7 +51,7 @@ VALUE zstds_ext_train_dictionary_buffer(VALUE ZSTDS_EXT_UNUSED(self), VALUE samp
|
|
54
51
|
zstds_ext_raise_error(ZSTDS_EXT_ERROR_ALLOCATE_FAILED);
|
55
52
|
}
|
56
53
|
|
57
|
-
|
54
|
+
zstds_ext_byte_t* samples_buffer = malloc(samples_size);
|
58
55
|
if (samples_buffer == NULL) {
|
59
56
|
zstds_ext_raise_error(ZSTDS_EXT_ERROR_ALLOCATE_FAILED);
|
60
57
|
}
|
data/ext/zstds_ext/error.c
CHANGED
data/ext/zstds_ext/io.c
CHANGED
@@ -3,14 +3,11 @@
|
|
3
3
|
|
4
4
|
#include "ruby/io.h"
|
5
5
|
|
6
|
-
#include <stdint.h>
|
7
6
|
#include <stdio.h>
|
8
|
-
#include <stdlib.h>
|
9
7
|
#include <string.h>
|
10
8
|
#include <zstd.h>
|
11
9
|
|
12
10
|
#include "ruby.h"
|
13
|
-
#include "zstds_ext/common.h"
|
14
11
|
#include "zstds_ext/error.h"
|
15
12
|
#include "zstds_ext/io.h"
|
16
13
|
#include "zstds_ext/macro.h"
|
@@ -23,7 +20,7 @@ enum {
|
|
23
20
|
|
24
21
|
// -- file --
|
25
22
|
|
26
|
-
static inline zstds_ext_result_t read_file(FILE* source_file,
|
23
|
+
static inline zstds_ext_result_t read_file(FILE* source_file, zstds_ext_byte_t* source_buffer, size_t* source_length_ptr, size_t source_buffer_length)
|
27
24
|
{
|
28
25
|
size_t read_length = fread(source_buffer, 1, source_buffer_length, source_file);
|
29
26
|
if (read_length == 0 && feof(source_file)) {
|
@@ -39,7 +36,7 @@ static inline zstds_ext_result_t read_file(FILE* source_file, uint8_t* source_bu
|
|
39
36
|
return 0;
|
40
37
|
}
|
41
38
|
|
42
|
-
static inline zstds_ext_result_t write_file(FILE* destination_file,
|
39
|
+
static inline zstds_ext_result_t write_file(FILE* destination_file, zstds_ext_byte_t* destination_buffer, size_t destination_length)
|
43
40
|
{
|
44
41
|
size_t written_length = fwrite(destination_buffer, 1, destination_length, destination_file);
|
45
42
|
if (written_length != destination_length) {
|
@@ -52,15 +49,15 @@ static inline zstds_ext_result_t write_file(FILE* destination_file, uint8_t* des
|
|
52
49
|
// -- buffer --
|
53
50
|
|
54
51
|
static inline zstds_ext_result_t create_buffers(
|
55
|
-
|
56
|
-
|
52
|
+
zstds_ext_byte_t** source_buffer_ptr, size_t source_buffer_length,
|
53
|
+
zstds_ext_byte_t** destination_buffer_ptr, size_t destination_buffer_length)
|
57
54
|
{
|
58
|
-
|
55
|
+
zstds_ext_byte_t* source_buffer = malloc(source_buffer_length);
|
59
56
|
if (source_buffer == NULL) {
|
60
57
|
return ZSTDS_EXT_ERROR_ALLOCATE_FAILED;
|
61
58
|
}
|
62
59
|
|
63
|
-
|
60
|
+
zstds_ext_byte_t* destination_buffer = malloc(destination_buffer_length);
|
64
61
|
if (destination_buffer == NULL) {
|
65
62
|
free(source_buffer);
|
66
63
|
return ZSTDS_EXT_ERROR_ALLOCATE_FAILED;
|
@@ -79,12 +76,12 @@ static inline zstds_ext_result_t create_buffers(
|
|
79
76
|
// Algorithm can use same buffer again.
|
80
77
|
|
81
78
|
static inline zstds_ext_result_t read_more_source(
|
82
|
-
FILE*
|
83
|
-
const
|
84
|
-
|
79
|
+
FILE* source_file,
|
80
|
+
const zstds_ext_byte_t** source_ptr, size_t* source_length_ptr,
|
81
|
+
zstds_ext_byte_t* source_buffer, size_t source_buffer_length)
|
85
82
|
{
|
86
|
-
const
|
87
|
-
size_t
|
83
|
+
const zstds_ext_byte_t* source = *source_ptr;
|
84
|
+
size_t source_length = *source_length_ptr;
|
88
85
|
|
89
86
|
if (source != source_buffer) {
|
90
87
|
if (source_length != 0) {
|
@@ -101,8 +98,8 @@ static inline zstds_ext_result_t read_more_source(
|
|
101
98
|
return ZSTDS_EXT_ERROR_NOT_ENOUGH_SOURCE_BUFFER;
|
102
99
|
}
|
103
100
|
|
104
|
-
|
105
|
-
size_t
|
101
|
+
zstds_ext_byte_t* remaining_source_buffer = source_buffer + source_length;
|
102
|
+
size_t new_source_length;
|
106
103
|
|
107
104
|
zstds_ext_result_t ext_result = read_file(source_file, remaining_source_buffer, &new_source_length, remaining_source_buffer_length);
|
108
105
|
if (ext_result != 0) {
|
@@ -157,8 +154,8 @@ static inline zstds_ext_result_t read_more_source(
|
|
157
154
|
// Than algorithm can use same buffer again.
|
158
155
|
|
159
156
|
static inline zstds_ext_result_t flush_destination_buffer(
|
160
|
-
FILE*
|
161
|
-
|
157
|
+
FILE* destination_file,
|
158
|
+
zstds_ext_byte_t* destination_buffer, size_t* destination_length_ptr, size_t destination_buffer_length)
|
162
159
|
{
|
163
160
|
if (*destination_length_ptr == 0) {
|
164
161
|
// We want to write more data at once, than buffer has.
|
@@ -175,7 +172,7 @@ static inline zstds_ext_result_t flush_destination_buffer(
|
|
175
172
|
return 0;
|
176
173
|
}
|
177
174
|
|
178
|
-
static inline zstds_ext_result_t write_remaining_destination(FILE* destination_file,
|
175
|
+
static inline zstds_ext_result_t write_remaining_destination(FILE* destination_file, zstds_ext_byte_t* destination_buffer, size_t destination_length)
|
179
176
|
{
|
180
177
|
if (destination_length == 0) {
|
181
178
|
return 0;
|
@@ -200,9 +197,9 @@ static inline zstds_ext_result_t write_remaining_destination(FILE* destination_f
|
|
200
197
|
// -- compress --
|
201
198
|
|
202
199
|
static inline zstds_ext_result_t buffered_compress(
|
203
|
-
ZSTD_CCtx*
|
204
|
-
const
|
205
|
-
FILE* destination_file,
|
200
|
+
ZSTD_CCtx* ctx,
|
201
|
+
const zstds_ext_byte_t** source_ptr, size_t* source_length_ptr,
|
202
|
+
FILE* destination_file, zstds_ext_byte_t* destination_buffer, size_t* destination_length_ptr, size_t destination_buffer_length)
|
206
203
|
{
|
207
204
|
zstds_result_t result;
|
208
205
|
zstds_ext_result_t ext_result;
|
@@ -249,7 +246,7 @@ static inline zstds_ext_result_t buffered_compress(
|
|
249
246
|
|
250
247
|
static inline zstds_ext_result_t buffered_compressor_finish(
|
251
248
|
ZSTD_CCtx* ctx,
|
252
|
-
FILE* destination_file,
|
249
|
+
FILE* destination_file, zstds_ext_byte_t* destination_buffer, size_t* destination_length_ptr, size_t destination_buffer_length)
|
253
250
|
{
|
254
251
|
zstds_result_t result;
|
255
252
|
zstds_ext_result_t ext_result;
|
@@ -293,14 +290,14 @@ static inline zstds_ext_result_t buffered_compressor_finish(
|
|
293
290
|
|
294
291
|
static inline zstds_ext_result_t compress(
|
295
292
|
ZSTD_CCtx* ctx,
|
296
|
-
FILE* source_file,
|
297
|
-
FILE* destination_file,
|
293
|
+
FILE* source_file, zstds_ext_byte_t* source_buffer, size_t source_buffer_length,
|
294
|
+
FILE* destination_file, zstds_ext_byte_t* destination_buffer, size_t destination_buffer_length)
|
298
295
|
{
|
299
296
|
zstds_ext_result_t ext_result;
|
300
297
|
|
301
|
-
const
|
302
|
-
size_t
|
303
|
-
size_t
|
298
|
+
const zstds_ext_byte_t* source = source_buffer;
|
299
|
+
size_t source_length = 0;
|
300
|
+
size_t destination_length = 0;
|
304
301
|
|
305
302
|
BUFFERED_READ_SOURCE(
|
306
303
|
buffered_compress,
|
@@ -346,8 +343,8 @@ VALUE zstds_ext_compress_io(VALUE ZSTDS_EXT_UNUSED(self), VALUE source, VALUE de
|
|
346
343
|
destination_buffer_length = ZSTD_CStreamOutSize();
|
347
344
|
}
|
348
345
|
|
349
|
-
|
350
|
-
|
346
|
+
zstds_ext_byte_t* source_buffer;
|
347
|
+
zstds_ext_byte_t* destination_buffer;
|
351
348
|
|
352
349
|
ext_result = create_buffers(
|
353
350
|
&source_buffer, source_buffer_length,
|
@@ -380,9 +377,9 @@ VALUE zstds_ext_compress_io(VALUE ZSTDS_EXT_UNUSED(self), VALUE source, VALUE de
|
|
380
377
|
// -- decompress --
|
381
378
|
|
382
379
|
static inline zstds_ext_result_t buffered_decompress(
|
383
|
-
ZSTD_DCtx*
|
384
|
-
const
|
385
|
-
FILE* destination_file,
|
380
|
+
ZSTD_DCtx* ctx,
|
381
|
+
const zstds_ext_byte_t** source_ptr, size_t* source_length_ptr,
|
382
|
+
FILE* destination_file, zstds_ext_byte_t* destination_buffer, size_t* destination_length_ptr, size_t destination_buffer_length)
|
386
383
|
{
|
387
384
|
zstds_result_t result;
|
388
385
|
zstds_ext_result_t ext_result;
|
@@ -429,14 +426,14 @@ static inline zstds_ext_result_t buffered_decompress(
|
|
429
426
|
|
430
427
|
static inline zstds_ext_result_t decompress(
|
431
428
|
ZSTD_DCtx* ctx,
|
432
|
-
FILE* source_file,
|
433
|
-
FILE* destination_file,
|
429
|
+
FILE* source_file, zstds_ext_byte_t* source_buffer, size_t source_buffer_length,
|
430
|
+
FILE* destination_file, zstds_ext_byte_t* destination_buffer, size_t destination_buffer_length)
|
434
431
|
{
|
435
432
|
zstds_ext_result_t ext_result;
|
436
433
|
|
437
|
-
const
|
438
|
-
size_t
|
439
|
-
size_t
|
434
|
+
const zstds_ext_byte_t* source = source_buffer;
|
435
|
+
size_t source_length = 0;
|
436
|
+
size_t destination_length = 0;
|
440
437
|
|
441
438
|
BUFFERED_READ_SOURCE(
|
442
439
|
buffered_decompress,
|
@@ -474,8 +471,8 @@ VALUE zstds_ext_decompress_io(VALUE ZSTDS_EXT_UNUSED(self), VALUE source, VALUE
|
|
474
471
|
destination_buffer_length = ZSTD_DStreamOutSize();
|
475
472
|
}
|
476
473
|
|
477
|
-
|
478
|
-
|
474
|
+
zstds_ext_byte_t* source_buffer;
|
475
|
+
zstds_ext_byte_t* destination_buffer;
|
479
476
|
|
480
477
|
ext_result = create_buffers(
|
481
478
|
&source_buffer, source_buffer_length,
|
data/ext/zstds_ext/main.c
CHANGED
data/ext/zstds_ext/option.c
CHANGED
data/ext/zstds_ext/option.h
CHANGED
@@ -5,8 +5,6 @@
|
|
5
5
|
#define ZSTDS_EXT_OPTIONS_H
|
6
6
|
|
7
7
|
#include <stdbool.h>
|
8
|
-
#include <stdint.h>
|
9
|
-
#include <stdlib.h>
|
10
8
|
#include <zstd.h>
|
11
9
|
|
12
10
|
#include "ruby.h"
|
@@ -22,9 +20,9 @@ enum {
|
|
22
20
|
ZSTDS_EXT_OPTION_TYPE_STRATEGY
|
23
21
|
};
|
24
22
|
|
25
|
-
typedef
|
26
|
-
typedef int
|
27
|
-
typedef unsigned long long
|
23
|
+
typedef zstds_ext_byte_fast_t zstds_ext_option_type_t;
|
24
|
+
typedef int zstds_ext_option_value_t;
|
25
|
+
typedef unsigned long long zstds_ext_ull_option_value_t;
|
28
26
|
|
29
27
|
typedef struct {
|
30
28
|
bool has_value;
|
@@ -3,12 +3,9 @@
|
|
3
3
|
|
4
4
|
#include "zstds_ext/stream/compressor.h"
|
5
5
|
|
6
|
-
#include <stdint.h>
|
7
|
-
#include <stdlib.h>
|
8
6
|
#include <zstd.h>
|
9
7
|
|
10
8
|
#include "ruby.h"
|
11
|
-
#include "zstds_ext/common.h"
|
12
9
|
#include "zstds_ext/error.h"
|
13
10
|
#include "zstds_ext/option.h"
|
14
11
|
|
@@ -19,7 +16,7 @@ static void free_compressor(zstds_ext_compressor_t* compressor_ptr)
|
|
19
16
|
ZSTD_freeCCtx(ctx);
|
20
17
|
}
|
21
18
|
|
22
|
-
|
19
|
+
zstds_ext_byte_t* destination_buffer = compressor_ptr->destination_buffer;
|
23
20
|
if (destination_buffer != NULL) {
|
24
21
|
free(destination_buffer);
|
25
22
|
}
|
@@ -68,7 +65,7 @@ VALUE zstds_ext_initialize_compressor(VALUE self, VALUE options)
|
|
68
65
|
destination_buffer_length = ZSTD_CStreamOutSize();
|
69
66
|
}
|
70
67
|
|
71
|
-
|
68
|
+
zstds_ext_byte_t* destination_buffer = malloc(destination_buffer_length);
|
72
69
|
if (destination_buffer == NULL) {
|
73
70
|
ZSTD_freeCCtx(ctx);
|
74
71
|
zstds_ext_raise_error(ZSTDS_EXT_ERROR_ALLOCATE_FAILED);
|
@@ -185,9 +182,9 @@ VALUE zstds_ext_compressor_read_result(VALUE self)
|
|
185
182
|
GET_COMPRESSOR(self);
|
186
183
|
DO_NOT_USE_AFTER_CLOSE(compressor_ptr);
|
187
184
|
|
188
|
-
|
189
|
-
size_t
|
190
|
-
size_t
|
185
|
+
zstds_ext_byte_t* destination_buffer = compressor_ptr->destination_buffer;
|
186
|
+
size_t destination_buffer_length = compressor_ptr->destination_buffer_length;
|
187
|
+
size_t remaining_destination_buffer_length = compressor_ptr->remaining_destination_buffer_length;
|
191
188
|
|
192
189
|
const char* result = (const char*)destination_buffer;
|
193
190
|
size_t result_length = destination_buffer_length - remaining_destination_buffer_length;
|
@@ -212,7 +209,7 @@ VALUE zstds_ext_compressor_close(VALUE self)
|
|
212
209
|
compressor_ptr->ctx = NULL;
|
213
210
|
}
|
214
211
|
|
215
|
-
|
212
|
+
zstds_ext_byte_t* destination_buffer = compressor_ptr->destination_buffer;
|
216
213
|
if (destination_buffer != NULL) {
|
217
214
|
free(destination_buffer);
|
218
215
|
|
@@ -4,18 +4,17 @@
|
|
4
4
|
#if !defined(ZSTDS_EXT_STREAM_COMPRESSOR_H)
|
5
5
|
#define ZSTDS_EXT_STREAM_COMPRESSOR_H
|
6
6
|
|
7
|
-
#include <stdint.h>
|
8
|
-
#include <stdlib.h>
|
9
7
|
#include <zstd.h>
|
10
8
|
|
11
9
|
#include "ruby.h"
|
10
|
+
#include "zstds_ext/common.h"
|
12
11
|
|
13
12
|
typedef struct {
|
14
|
-
ZSTD_CCtx*
|
15
|
-
|
16
|
-
size_t
|
17
|
-
|
18
|
-
size_t
|
13
|
+
ZSTD_CCtx* ctx;
|
14
|
+
zstds_ext_byte_t* destination_buffer;
|
15
|
+
size_t destination_buffer_length;
|
16
|
+
zstds_ext_byte_t* remaining_destination_buffer;
|
17
|
+
size_t remaining_destination_buffer_length;
|
19
18
|
} zstds_ext_compressor_t;
|
20
19
|
|
21
20
|
VALUE zstds_ext_allocate_compressor(VALUE klass);
|
@@ -3,12 +3,9 @@
|
|
3
3
|
|
4
4
|
#include "zstds_ext/stream/decompressor.h"
|
5
5
|
|
6
|
-
#include <stdint.h>
|
7
|
-
#include <stdlib.h>
|
8
6
|
#include <zstd.h>
|
9
7
|
|
10
8
|
#include "ruby.h"
|
11
|
-
#include "zstds_ext/common.h"
|
12
9
|
#include "zstds_ext/error.h"
|
13
10
|
#include "zstds_ext/option.h"
|
14
11
|
|
@@ -19,7 +16,7 @@ static void free_decompressor(zstds_ext_decompressor_t* decompressor_ptr)
|
|
19
16
|
ZSTD_freeDCtx(ctx);
|
20
17
|
}
|
21
18
|
|
22
|
-
|
19
|
+
zstds_ext_byte_t* destination_buffer = decompressor_ptr->destination_buffer;
|
23
20
|
if (destination_buffer != NULL) {
|
24
21
|
free(destination_buffer);
|
25
22
|
}
|
@@ -68,7 +65,7 @@ VALUE zstds_ext_initialize_decompressor(VALUE self, VALUE options)
|
|
68
65
|
destination_buffer_length = ZSTD_DStreamOutSize();
|
69
66
|
}
|
70
67
|
|
71
|
-
|
68
|
+
zstds_ext_byte_t* destination_buffer = malloc(destination_buffer_length);
|
72
69
|
if (destination_buffer == NULL) {
|
73
70
|
ZSTD_freeDCtx(ctx);
|
74
71
|
zstds_ext_raise_error(ZSTDS_EXT_ERROR_ALLOCATE_FAILED);
|
@@ -129,9 +126,9 @@ VALUE zstds_ext_decompressor_read_result(VALUE self)
|
|
129
126
|
GET_DECOMPRESSOR(self);
|
130
127
|
DO_NOT_USE_AFTER_CLOSE(decompressor_ptr);
|
131
128
|
|
132
|
-
|
133
|
-
size_t
|
134
|
-
size_t
|
129
|
+
zstds_ext_byte_t* destination_buffer = decompressor_ptr->destination_buffer;
|
130
|
+
size_t destination_buffer_length = decompressor_ptr->destination_buffer_length;
|
131
|
+
size_t remaining_destination_buffer_length = decompressor_ptr->remaining_destination_buffer_length;
|
135
132
|
|
136
133
|
const char* result = (const char*)destination_buffer;
|
137
134
|
size_t result_length = destination_buffer_length - remaining_destination_buffer_length;
|
@@ -156,7 +153,7 @@ VALUE zstds_ext_decompressor_close(VALUE self)
|
|
156
153
|
decompressor_ptr->ctx = NULL;
|
157
154
|
}
|
158
155
|
|
159
|
-
|
156
|
+
zstds_ext_byte_t* destination_buffer = decompressor_ptr->destination_buffer;
|
160
157
|
if (destination_buffer != NULL) {
|
161
158
|
free(destination_buffer);
|
162
159
|
|
@@ -4,18 +4,17 @@
|
|
4
4
|
#if !defined(ZSTDS_EXT_STREAM_DECOMPRESSOR_H)
|
5
5
|
#define ZSTDS_EXT_STREAM_DECOMPRESSOR_H
|
6
6
|
|
7
|
-
#include <stdint.h>
|
8
|
-
#include <stdlib.h>
|
9
7
|
#include <zstd.h>
|
10
8
|
|
11
9
|
#include "ruby.h"
|
10
|
+
#include "zstds_ext/common.h"
|
12
11
|
|
13
12
|
typedef struct {
|
14
|
-
ZSTD_DCtx*
|
15
|
-
|
16
|
-
size_t
|
17
|
-
|
18
|
-
size_t
|
13
|
+
ZSTD_DCtx* ctx;
|
14
|
+
zstds_ext_byte_t* destination_buffer;
|
15
|
+
size_t destination_buffer_length;
|
16
|
+
zstds_ext_byte_t* remaining_destination_buffer;
|
17
|
+
size_t remaining_destination_buffer_length;
|
19
18
|
} zstds_ext_decompressor_t;
|
20
19
|
|
21
20
|
VALUE zstds_ext_allocate_decompressor(VALUE klass);
|
data/ext/zstds_ext/string.c
CHANGED
@@ -3,13 +3,10 @@
|
|
3
3
|
|
4
4
|
#include "zstds_ext/string.h"
|
5
5
|
|
6
|
-
#include <stdint.h>
|
7
|
-
#include <stdlib.h>
|
8
6
|
#include <zstd.h>
|
9
7
|
|
10
8
|
#include "ruby.h"
|
11
9
|
#include "zstds_ext/buffer.h"
|
12
|
-
#include "zstds_ext/common.h"
|
13
10
|
#include "zstds_ext/error.h"
|
14
11
|
#include "zstds_ext/macro.h"
|
15
12
|
#include "zstds_ext/option.h"
|
@@ -65,7 +62,7 @@ static inline zstds_ext_result_t compress(
|
|
65
62
|
size_t remaining_destination_buffer_length = destination_buffer_length;
|
66
63
|
|
67
64
|
while (true) {
|
68
|
-
out_buffer.dst = (
|
65
|
+
out_buffer.dst = (zstds_ext_byte_t*)RSTRING_PTR(destination_value) + destination_length;
|
69
66
|
out_buffer.size = remaining_destination_buffer_length;
|
70
67
|
out_buffer.pos = 0;
|
71
68
|
|
@@ -166,7 +163,7 @@ static inline zstds_ext_result_t decompress(
|
|
166
163
|
size_t remaining_destination_buffer_length = destination_buffer_length;
|
167
164
|
|
168
165
|
while (true) {
|
169
|
-
out_buffer.dst = (
|
166
|
+
out_buffer.dst = (zstds_ext_byte_t*)RSTRING_PTR(destination_value) + destination_length;
|
170
167
|
out_buffer.size = remaining_destination_buffer_length;
|
171
168
|
out_buffer.pos = 0;
|
172
169
|
|
@@ -23,17 +23,18 @@ module ZSTDS
|
|
23
23
|
attr_reader :internal_encoding
|
24
24
|
attr_reader :transcode_options
|
25
25
|
attr_reader :pos
|
26
|
+
|
26
27
|
alias tell pos
|
27
28
|
|
28
|
-
def initialize(io,
|
29
|
+
def initialize(io, options = {})
|
29
30
|
@raw_stream = create_raw_stream
|
30
31
|
|
31
32
|
Validation.validate_io io
|
32
33
|
@io = io
|
33
34
|
|
34
|
-
@stat = Stat.new @io.stat
|
35
|
+
@stat = Stat.new @io.stat if @io.respond_to? :stat
|
35
36
|
|
36
|
-
set_encoding external_encoding, internal_encoding, transcode_options
|
37
|
+
set_encoding options[:external_encoding], options[:internal_encoding], options[:transcode_options]
|
37
38
|
reset_buffer
|
38
39
|
reset_io_advise
|
39
40
|
|
@@ -50,8 +51,8 @@ module ZSTDS
|
|
50
51
|
|
51
52
|
protected def reset_io_advise
|
52
53
|
# Both compressor and decompressor need sequential io access.
|
53
|
-
@io.advise :sequential
|
54
|
-
rescue ::Errno::ESPIPE
|
54
|
+
@io.advise :sequential if @io.respond_to? :advise
|
55
|
+
rescue ::Errno::ESPIPE
|
55
56
|
# ok
|
56
57
|
end
|
57
58
|
|
@@ -126,7 +127,8 @@ module ZSTDS
|
|
126
127
|
def rewind
|
127
128
|
@raw_stream = create_raw_stream
|
128
129
|
|
129
|
-
@io.rewind
|
130
|
+
@io.rewind if @io.respond_to? :rewind
|
131
|
+
|
130
132
|
reset_buffer
|
131
133
|
reset_io_advise
|
132
134
|
|
data/lib/zstds/stream/reader.rb
CHANGED
@@ -147,7 +147,7 @@ module ZSTDS
|
|
147
147
|
end
|
148
148
|
|
149
149
|
protected def transcode_to_internal(data)
|
150
|
-
data = data.encode @internal_encoding,
|
150
|
+
data = data.encode @internal_encoding, **@transcode_options unless @internal_encoding.nil?
|
151
151
|
data
|
152
152
|
end
|
153
153
|
|
data/lib/zstds/stream/writer.rb
CHANGED
@@ -137,7 +137,7 @@ module ZSTDS
|
|
137
137
|
# -- common --
|
138
138
|
|
139
139
|
protected def transcode(data)
|
140
|
-
data = data.encode @external_encoding,
|
140
|
+
data = data.encode @external_encoding, **@transcode_options unless @external_encoding.nil?
|
141
141
|
data
|
142
142
|
end
|
143
143
|
end
|
@@ -13,13 +13,13 @@ module ZSTDS
|
|
13
13
|
write object
|
14
14
|
end
|
15
15
|
|
16
|
-
def print(*objects)
|
16
|
+
def print(*objects, field_separator: $OUTPUT_FIELD_SEPARATOR, record_separator: $OUTPUT_RECORD_SEPARATOR)
|
17
17
|
objects.each do |object|
|
18
18
|
write object
|
19
|
-
write
|
19
|
+
write field_separator unless field_separator.nil?
|
20
20
|
end
|
21
21
|
|
22
|
-
write
|
22
|
+
write record_separator unless record_separator.nil?
|
23
23
|
|
24
24
|
nil
|
25
25
|
end
|
data/lib/zstds/validation.rb
CHANGED
@@ -5,6 +5,19 @@ require_relative "error"
|
|
5
5
|
|
6
6
|
module ZSTDS
|
7
7
|
module Validation
|
8
|
+
IO_METHODS = %i[
|
9
|
+
read
|
10
|
+
write
|
11
|
+
readpartial
|
12
|
+
read_nonblock
|
13
|
+
write_nonblock
|
14
|
+
eof?
|
15
|
+
flush
|
16
|
+
close
|
17
|
+
closed?
|
18
|
+
]
|
19
|
+
.freeze
|
20
|
+
|
8
21
|
def self.validate_bool(value)
|
9
22
|
raise ValidateError, "invalid bool" unless value.is_a?(::TrueClass) || value.is_a?(::FalseClass)
|
10
23
|
end
|
@@ -30,7 +43,7 @@ module ZSTDS
|
|
30
43
|
end
|
31
44
|
|
32
45
|
def self.validate_io(value)
|
33
|
-
raise ValidateError, "invalid io" unless value.
|
46
|
+
raise ValidateError, "invalid io" unless IO_METHODS.all? { |method| value.respond_to? method }
|
34
47
|
end
|
35
48
|
|
36
49
|
def self.validate_array(value)
|
data/lib/zstds/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby-zstds
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew Aladjev
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-06-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: codecov
|
@@ -217,7 +217,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
217
217
|
- !ruby/object:Gem::Version
|
218
218
|
version: '0'
|
219
219
|
requirements: []
|
220
|
-
rubygems_version: 3.
|
220
|
+
rubygems_version: 3.1.2
|
221
221
|
signing_key:
|
222
222
|
specification_version: 4
|
223
223
|
summary: Ruby bindings for zstd library.
|