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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 385a6f6c852fb6364739a194c7093286f59832078c9f934828c7219c74b08208
4
- data.tar.gz: c65081f337c79034e3bba1cd0ef852988bd81671cd4ffe962a249d2d999c4226
3
+ metadata.gz: e2279b518a90a526dd82247626f5969d01f6786de10b91802c5b6b7f3391ac26
4
+ data.tar.gz: 854b6e8d08c7cc2fa464e3acc25cf45ea6ff204809b5b2cb08cea94217e34b1f
5
5
  SHA512:
6
- metadata.gz: cc1903ed422256c4e1bc432b19a77211fde31ebaf76eff5c191aaf74e7dfa71d744266b45e57e21bb64a40c0f3a982c09ee5da1134e3d5ff0c957b588cfb6e47
7
- data.tar.gz: 18f7ce7cfea451b951544491cc7fdc79891f220c8cfb7a6b7cb99a7ae9f99c4154c2f173908a673c70ad2e9d741ddbbd4d26fb73f254d0284730d720654d8cb7
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.6.1/libdoc/zlib/rdoc/Zlib/GzipWriter.html).
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.6.1/IO.html) docs.
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.6.1/libdoc/zlib/rdoc/Zlib/GzipWriter.html) docs.
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.6.1/libdoc/zlib/rdoc/Zlib/GzipWriter.html) docs.
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.6.1/libdoc/zlib/rdoc/Zlib/GzipReader.html).
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.6.1/IO.html) docs.
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.6.1/libdoc/zlib/rdoc/Zlib/GzipReader.html) docs.
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.6.1/IO.html) docs.
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.6.1/libdoc/zlib/rdoc/Zlib/GzipReader.html) docs.
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
- Travis and Appveyor CI uses [scripts/ci_test.sh](scripts/ci_test.sh) directly.
493
- Cirrus and Circle CI uses prebuilt [scripts/test-images](scripts/test-images).
494
- Cirrus CI uses amd64 image, Circle CI - i686.
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
 
@@ -13,4 +13,7 @@
13
13
  typedef size_t zstds_result_t;
14
14
  typedef uint_fast8_t zstds_ext_result_t;
15
15
 
16
+ typedef uint8_t zstds_ext_byte_t;
17
+ typedef uint_fast8_t zstds_ext_byte_fast_t;
18
+
16
19
  #endif // ZSTDS_EXT_COMMON_H
@@ -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
- uint8_t* samples_buffer = malloc(samples_size);
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
  }
@@ -6,7 +6,6 @@
6
6
  #include <zstd_errors.h>
7
7
 
8
8
  #include "ruby.h"
9
- #include "zstds_ext/common.h"
10
9
 
11
10
  zstds_ext_result_t zstds_ext_get_error(ZSTD_ErrorCode error_code)
12
11
  {
@@ -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, uint8_t* source_buffer, size_t* source_length_ptr, size_t source_buffer_length)
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, uint8_t* destination_buffer, size_t destination_length)
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
- uint8_t** source_buffer_ptr, size_t source_buffer_length,
56
- uint8_t** destination_buffer_ptr, size_t destination_buffer_length)
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
- uint8_t* source_buffer = malloc(source_buffer_length);
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
- uint8_t* destination_buffer = malloc(destination_buffer_length);
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* source_file,
83
- const uint8_t** source_ptr, size_t* source_length_ptr,
84
- uint8_t* source_buffer, size_t source_buffer_length)
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 uint8_t* source = *source_ptr;
87
- size_t source_length = *source_length_ptr;
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
- uint8_t* remaining_source_buffer = source_buffer + source_length;
105
- size_t new_source_length;
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* destination_file,
161
- uint8_t* destination_buffer, size_t* destination_length_ptr, size_t destination_buffer_length)
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, uint8_t* destination_buffer, size_t destination_length)
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* ctx,
204
- const uint8_t** source_ptr, size_t* source_length_ptr,
205
- FILE* destination_file, uint8_t* destination_buffer, size_t* destination_length_ptr, size_t destination_buffer_length)
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, uint8_t* destination_buffer, size_t* destination_length_ptr, size_t destination_buffer_length)
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, uint8_t* source_buffer, size_t source_buffer_length,
297
- FILE* destination_file, uint8_t* destination_buffer, size_t destination_buffer_length)
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 uint8_t* source = source_buffer;
302
- size_t source_length = 0;
303
- size_t destination_length = 0;
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
- uint8_t* source_buffer;
350
- uint8_t* destination_buffer;
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* ctx,
384
- const uint8_t** source_ptr, size_t* source_length_ptr,
385
- FILE* destination_file, uint8_t* destination_buffer, size_t* destination_length_ptr, size_t destination_buffer_length)
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, uint8_t* source_buffer, size_t source_buffer_length,
433
- FILE* destination_file, uint8_t* destination_buffer, size_t destination_buffer_length)
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 uint8_t* source = source_buffer;
438
- size_t source_length = 0;
439
- size_t destination_length = 0;
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
- uint8_t* source_buffer;
478
- uint8_t* destination_buffer;
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,
@@ -3,7 +3,6 @@
3
3
 
4
4
  #include "ruby.h"
5
5
  #include "zstds_ext/buffer.h"
6
- #include "zstds_ext/common.h"
7
6
  #include "zstds_ext/dictionary.h"
8
7
  #include "zstds_ext/io.h"
9
8
  #include "zstds_ext/option.h"
@@ -3,13 +3,9 @@
3
3
 
4
4
  #include "zstds_ext/option.h"
5
5
 
6
- #include <stdbool.h>
7
- #include <stdint.h>
8
- #include <stdlib.h>
9
6
  #include <zstd.h>
10
7
 
11
8
  #include "ruby.h"
12
- #include "zstds_ext/common.h"
13
9
  #include "zstds_ext/dictionary.h"
14
10
  #include "zstds_ext/error.h"
15
11
 
@@ -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 uint_fast8_t zstds_ext_option_type_t;
26
- typedef int zstds_ext_option_value_t;
27
- typedef unsigned long long zstds_ext_ull_option_value_t;
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
- uint8_t* destination_buffer = compressor_ptr->destination_buffer;
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
- uint8_t* destination_buffer = malloc(destination_buffer_length);
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
- uint8_t* destination_buffer = compressor_ptr->destination_buffer;
189
- size_t destination_buffer_length = compressor_ptr->destination_buffer_length;
190
- size_t remaining_destination_buffer_length = compressor_ptr->remaining_destination_buffer_length;
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
- uint8_t* destination_buffer = compressor_ptr->destination_buffer;
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* ctx;
15
- uint8_t* destination_buffer;
16
- size_t destination_buffer_length;
17
- uint8_t* remaining_destination_buffer;
18
- size_t remaining_destination_buffer_length;
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
- uint8_t* destination_buffer = decompressor_ptr->destination_buffer;
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
- uint8_t* destination_buffer = malloc(destination_buffer_length);
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
- uint8_t* destination_buffer = decompressor_ptr->destination_buffer;
133
- size_t destination_buffer_length = decompressor_ptr->destination_buffer_length;
134
- size_t remaining_destination_buffer_length = decompressor_ptr->remaining_destination_buffer_length;
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
- uint8_t* destination_buffer = decompressor_ptr->destination_buffer;
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* ctx;
15
- uint8_t* destination_buffer;
16
- size_t destination_buffer_length;
17
- uint8_t* remaining_destination_buffer;
18
- size_t remaining_destination_buffer_length;
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);
@@ -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 = (uint8_t*)RSTRING_PTR(destination_value) + destination_length;
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 = (uint8_t*)RSTRING_PTR(destination_value) + destination_length;
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, external_encoding: nil, internal_encoding: nil, transcode_options: {})
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 # rubocop:disable Lint/SuppressedException
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
 
@@ -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, @transcode_options unless @internal_encoding.nil?
150
+ data = data.encode @internal_encoding, **@transcode_options unless @internal_encoding.nil?
151
151
  data
152
152
  end
153
153
 
@@ -137,7 +137,7 @@ module ZSTDS
137
137
  # -- common --
138
138
 
139
139
  protected def transcode(data)
140
- data = data.encode @external_encoding, @transcode_options unless @external_encoding.nil?
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 $OUTPUT_FIELD_SEPARATOR unless $OUTPUT_FIELD_SEPARATOR.nil?
19
+ write field_separator unless field_separator.nil?
20
20
  end
21
21
 
22
- write $OUTPUT_RECORD_SEPARATOR unless $OUTPUT_RECORD_SEPARATOR.nil?
22
+ write record_separator unless record_separator.nil?
23
23
 
24
24
  nil
25
25
  end
@@ -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.is_a? ::IO
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)
@@ -2,5 +2,5 @@
2
2
  # Copyright (c) 2019 AUTHORS, MIT License.
3
3
 
4
4
  module ZSTDS
5
- VERSION = "1.0.2".freeze
5
+ VERSION = "1.0.3".freeze
6
6
  end
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.2
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-01-02 00:00:00.000000000 Z
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.0.6
220
+ rubygems_version: 3.1.2
221
221
  signing_key:
222
222
  specification_version: 4
223
223
  summary: Ruby bindings for zstd library.