ruby-brs 1.1.1 → 1.1.2

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: 774954dc3bd3496501331c3799402c19bb6cd683fb0852420228677c8cc9bee5
4
- data.tar.gz: 162bbb4c99689035c3c2a245ba0c242886c1f75eab278ce1082984110896366e
3
+ metadata.gz: f79255ffdaf743bde0edc13c314d1cf7f12402a9993389d6a86dea3d449b4e21
4
+ data.tar.gz: 8ca40ddca9e58f2876c33bd17bc353bdb739cf79d344ff5bf3c217c52a9cd2ac
5
5
  SHA512:
6
- metadata.gz: 2560264e86f2ff77dd810261d94576d9999682c5f9f70334d2e85d28dfc7e576bd1e996872020b65e3588d3334e019d3a6c056960ddcd0cbe98c406fc2794c6c
7
- data.tar.gz: fef04f25c06b4cdac5b187feced270ca021361c4c112db269d7509dea636fdf53d492d10566b137889dea543433ed332ec1e8d643163233f0db8657c03342dc5
6
+ metadata.gz: 801a6df0e461a1df124647362c10a6af08d0e5621ef5682987d6d0615b548e3fa51d5c184afd804be33cf4da74ce0ef810f8209851f5b5efe31037ac6912f205
7
+ data.tar.gz: ef62bbc6958e7de16d59eb0a56f84cc9c7ae7f88738219d642562455d7d7815df29cd94fa32da7f23dbf7065310c46e0081e3d0ce0443af8aa5d0257d1a765ba
data/README.md CHANGED
@@ -190,7 +190,7 @@ File maintains both source and destination buffers, it accepts both `source_buff
190
190
 
191
191
  ## Stream::Writer
192
192
 
193
- Its behaviour is similar to builtin [`Zlib::GzipWriter`](https://ruby-doc.org/stdlib-2.6.1/libdoc/zlib/rdoc/Zlib/GzipWriter.html).
193
+ Its behaviour is similar to builtin [`Zlib::GzipWriter`](https://ruby-doc.org/stdlib-2.7.0/libdoc/zlib/rdoc/Zlib/GzipWriter.html).
194
194
 
195
195
  Writer maintains destination buffer only, so it accepts `destination_buffer_length` option only.
196
196
 
@@ -228,7 +228,7 @@ Set another encodings, `nil` is just for compatibility with `IO`.
228
228
  #tell
229
229
  ```
230
230
 
231
- See [`IO`](https://ruby-doc.org/core-2.6.1/IO.html) docs.
231
+ See [`IO`](https://ruby-doc.org/core-2.7.0/IO.html) docs.
232
232
 
233
233
  ```
234
234
  #write(*objects)
@@ -238,7 +238,7 @@ See [`IO`](https://ruby-doc.org/core-2.6.1/IO.html) docs.
238
238
  #closed?
239
239
  ```
240
240
 
241
- See [`Zlib::GzipWriter`](https://ruby-doc.org/stdlib-2.6.1/libdoc/zlib/rdoc/Zlib/GzipWriter.html) docs.
241
+ See [`Zlib::GzipWriter`](https://ruby-doc.org/stdlib-2.7.0/libdoc/zlib/rdoc/Zlib/GzipWriter.html) docs.
242
242
 
243
243
  ```
244
244
  #write_nonblock(object, *options)
@@ -260,11 +260,11 @@ Behaviour is the same as `IO#write_nonblock` method.
260
260
  #puts(*objects)
261
261
  ```
262
262
 
263
- Typical helpers, see [`Zlib::GzipWriter`](https://ruby-doc.org/stdlib-2.6.1/libdoc/zlib/rdoc/Zlib/GzipWriter.html) docs.
263
+ Typical helpers, see [`Zlib::GzipWriter`](https://ruby-doc.org/stdlib-2.7.0/libdoc/zlib/rdoc/Zlib/GzipWriter.html) docs.
264
264
 
265
265
  ## Stream::Reader
266
266
 
267
- Its behaviour is similar to builtin [`Zlib::GzipReader`](https://ruby-doc.org/stdlib-2.6.1/libdoc/zlib/rdoc/Zlib/GzipReader.html).
267
+ Its behaviour is similar to builtin [`Zlib::GzipReader`](https://ruby-doc.org/stdlib-2.7.0/libdoc/zlib/rdoc/Zlib/GzipReader.html).
268
268
 
269
269
  Reader maintains both source and destination buffers, it accepts both `source_buffer_length` and `destination_buffer_length` options.
270
270
 
@@ -299,7 +299,7 @@ Set another encodings.
299
299
  #tell
300
300
  ```
301
301
 
302
- See [`IO`](https://ruby-doc.org/core-2.6.1/IO.html) docs.
302
+ See [`IO`](https://ruby-doc.org/core-2.7.0/IO.html) docs.
303
303
 
304
304
  ```
305
305
  #read(bytes_to_read = nil, out_buffer = nil)
@@ -309,14 +309,14 @@ See [`IO`](https://ruby-doc.org/core-2.6.1/IO.html) docs.
309
309
  #closed?
310
310
  ```
311
311
 
312
- See [`Zlib::GzipReader`](https://ruby-doc.org/stdlib-2.6.1/libdoc/zlib/rdoc/Zlib/GzipReader.html) docs.
312
+ See [`Zlib::GzipReader`](https://ruby-doc.org/stdlib-2.7.0/libdoc/zlib/rdoc/Zlib/GzipReader.html) docs.
313
313
 
314
314
  ```
315
315
  #readpartial(bytes_to_read = nil, out_buffer = nil)
316
316
  #read_nonblock(bytes_to_read, out_buffer = nil, *options)
317
317
  ```
318
318
 
319
- See [`IO`](https://ruby-doc.org/core-2.6.1/IO.html) docs.
319
+ See [`IO`](https://ruby-doc.org/core-2.7.0/IO.html) docs.
320
320
 
321
321
  ```
322
322
  #getbyte
@@ -339,13 +339,15 @@ See [`IO`](https://ruby-doc.org/core-2.6.1/IO.html) docs.
339
339
  #ungetline(line)
340
340
  ```
341
341
 
342
- Typical helpers, see [`Zlib::GzipReader`](https://ruby-doc.org/stdlib-2.6.1/libdoc/zlib/rdoc/Zlib/GzipReader.html) docs.
342
+ Typical helpers, see [`Zlib::GzipReader`](https://ruby-doc.org/stdlib-2.7.0/libdoc/zlib/rdoc/Zlib/GzipReader.html) docs.
343
343
 
344
344
  ## CI
345
345
 
346
- Travis and Appveyor CI uses [scripts/ci_test.sh](scripts/ci_test.sh) directly.
347
- Cirrus and Circle CI uses prebuilt [scripts/test-images](scripts/test-images).
348
- Cirrus CI uses amd64 image, Circle CI - i686.
346
+ See universal test script [scripts/ci_test.sh](scripts/ci_test.sh) for CI.
347
+ Please visit [scripts/test-images](scripts/test-images).
348
+ You can run this test script using many native and cross images.
349
+
350
+ Cirrus CI uses `x86_64-pc-linux-gnu` image, Circle CI - `x86_64-gentoo-linux-musl` image.
349
351
 
350
352
  ## License
351
353
 
@@ -10,4 +10,7 @@
10
10
 
11
11
  typedef uint_fast8_t brs_ext_result_t;
12
12
 
13
+ typedef uint8_t brs_ext_byte_t;
14
+ typedef uint_fast8_t brs_ext_byte_fast_t;
15
+
13
16
  #endif // BRS_EXT_COMMON_H
@@ -5,7 +5,6 @@
5
5
 
6
6
  #include <brotli/decode.h>
7
7
 
8
- #include "brs_ext/common.h"
9
8
  #include "ruby.h"
10
9
 
11
10
  brs_ext_result_t brs_ext_get_decompressor_error(BrotliDecoderErrorCode error_code)
@@ -6,13 +6,11 @@
6
6
  #include <brotli/decode.h>
7
7
  #include <brotli/encode.h>
8
8
  #include <brotli/types.h>
9
- #include <stdint.h>
10
9
  #include <stdio.h>
11
10
  #include <stdlib.h>
12
11
  #include <string.h>
13
12
 
14
13
  #include "brs_ext/buffer.h"
15
- #include "brs_ext/common.h"
16
14
  #include "brs_ext/error.h"
17
15
  #include "brs_ext/io.h"
18
16
  #include "brs_ext/macro.h"
@@ -26,7 +24,7 @@ enum {
26
24
 
27
25
  // -- file --
28
26
 
29
- static inline brs_ext_result_t read_file(FILE* source_file, uint8_t* source_buffer, size_t* source_length_ptr, size_t source_buffer_length)
27
+ static inline brs_ext_result_t read_file(FILE* source_file, brs_ext_byte_t* source_buffer, size_t* source_length_ptr, size_t source_buffer_length)
30
28
  {
31
29
  size_t read_length = fread(source_buffer, 1, source_buffer_length, source_file);
32
30
  if (read_length == 0 && feof(source_file)) {
@@ -42,7 +40,7 @@ static inline brs_ext_result_t read_file(FILE* source_file, uint8_t* source_buff
42
40
  return 0;
43
41
  }
44
42
 
45
- static inline brs_ext_result_t write_file(FILE* destination_file, uint8_t* destination_buffer, size_t destination_length)
43
+ static inline brs_ext_result_t write_file(FILE* destination_file, brs_ext_byte_t* destination_buffer, size_t destination_length)
46
44
  {
47
45
  size_t written_length = fwrite(destination_buffer, 1, destination_length, destination_file);
48
46
  if (written_length != destination_length) {
@@ -55,15 +53,15 @@ static inline brs_ext_result_t write_file(FILE* destination_file, uint8_t* desti
55
53
  // -- buffer --
56
54
 
57
55
  static inline brs_ext_result_t create_buffers(
58
- uint8_t** source_buffer_ptr, size_t source_buffer_length,
59
- uint8_t** destination_buffer_ptr, size_t destination_buffer_length)
56
+ brs_ext_byte_t** source_buffer_ptr, size_t source_buffer_length,
57
+ brs_ext_byte_t** destination_buffer_ptr, size_t destination_buffer_length)
60
58
  {
61
- uint8_t* source_buffer = malloc(source_buffer_length);
59
+ brs_ext_byte_t* source_buffer = malloc(source_buffer_length);
62
60
  if (source_buffer == NULL) {
63
61
  return BRS_EXT_ERROR_ALLOCATE_FAILED;
64
62
  }
65
63
 
66
- uint8_t* destination_buffer = malloc(destination_buffer_length);
64
+ brs_ext_byte_t* destination_buffer = malloc(destination_buffer_length);
67
65
  if (destination_buffer == NULL) {
68
66
  free(source_buffer);
69
67
  return BRS_EXT_ERROR_ALLOCATE_FAILED;
@@ -82,12 +80,12 @@ static inline brs_ext_result_t create_buffers(
82
80
  // Algorithm can use same buffer again.
83
81
 
84
82
  static inline brs_ext_result_t read_more_source(
85
- FILE* source_file,
86
- const uint8_t** source_ptr, size_t* source_length_ptr,
87
- uint8_t* source_buffer, size_t source_buffer_length)
83
+ FILE* source_file,
84
+ const brs_ext_byte_t** source_ptr, size_t* source_length_ptr,
85
+ brs_ext_byte_t* source_buffer, size_t source_buffer_length)
88
86
  {
89
- const uint8_t* source = *source_ptr;
90
- size_t source_length = *source_length_ptr;
87
+ const brs_ext_byte_t* source = *source_ptr;
88
+ size_t source_length = *source_length_ptr;
91
89
 
92
90
  if (source != source_buffer) {
93
91
  if (source_length != 0) {
@@ -104,8 +102,8 @@ static inline brs_ext_result_t read_more_source(
104
102
  return BRS_EXT_ERROR_NOT_ENOUGH_SOURCE_BUFFER;
105
103
  }
106
104
 
107
- uint8_t* remaining_source_buffer = source_buffer + source_length;
108
- size_t new_source_length;
105
+ brs_ext_byte_t* remaining_source_buffer = source_buffer + source_length;
106
+ size_t new_source_length;
109
107
 
110
108
  brs_ext_result_t ext_result = read_file(source_file, remaining_source_buffer, &new_source_length, remaining_source_buffer_length);
111
109
  if (ext_result != 0) {
@@ -160,8 +158,8 @@ static inline brs_ext_result_t read_more_source(
160
158
  // Than algorithm can use same buffer again.
161
159
 
162
160
  static inline brs_ext_result_t flush_destination_buffer(
163
- FILE* destination_file,
164
- uint8_t* destination_buffer, size_t* destination_length_ptr, size_t destination_buffer_length)
161
+ FILE* destination_file,
162
+ brs_ext_byte_t* destination_buffer, size_t* destination_length_ptr, size_t destination_buffer_length)
165
163
  {
166
164
  if (*destination_length_ptr == 0) {
167
165
  // We want to write more data at once, than buffer has.
@@ -178,7 +176,7 @@ static inline brs_ext_result_t flush_destination_buffer(
178
176
  return 0;
179
177
  }
180
178
 
181
- static inline brs_ext_result_t write_remaining_destination(FILE* destination_file, uint8_t* destination_buffer, size_t destination_length)
179
+ static inline brs_ext_result_t write_remaining_destination(FILE* destination_file, brs_ext_byte_t* destination_buffer, size_t destination_length)
182
180
  {
183
181
  if (destination_length == 0) {
184
182
  return 0;
@@ -203,17 +201,17 @@ static inline brs_ext_result_t write_remaining_destination(FILE* destination_fil
203
201
  // -- compress --
204
202
 
205
203
  static inline brs_ext_result_t buffered_compress(
206
- BrotliEncoderState* state_ptr,
207
- const uint8_t** source_ptr, size_t* source_length_ptr,
208
- FILE* destination_file, uint8_t* destination_buffer, size_t* destination_length_ptr, size_t destination_buffer_length)
204
+ BrotliEncoderState* state_ptr,
205
+ const brs_ext_byte_t** source_ptr, size_t* source_length_ptr,
206
+ FILE* destination_file, brs_ext_byte_t* destination_buffer, size_t* destination_length_ptr, size_t destination_buffer_length)
209
207
  {
210
208
  BROTLI_BOOL result;
211
209
  brs_ext_result_t ext_result;
212
210
 
213
211
  while (true) {
214
- uint8_t* remaining_destination_buffer = destination_buffer + *destination_length_ptr;
215
- size_t remaining_destination_buffer_length = destination_buffer_length - *destination_length_ptr;
216
- size_t prev_remaining_destination_buffer_length = remaining_destination_buffer_length;
212
+ brs_ext_byte_t* remaining_destination_buffer = destination_buffer + *destination_length_ptr;
213
+ size_t remaining_destination_buffer_length = destination_buffer_length - *destination_length_ptr;
214
+ size_t prev_remaining_destination_buffer_length = remaining_destination_buffer_length;
217
215
 
218
216
  result = BrotliEncoderCompressStream(
219
217
  state_ptr,
@@ -248,18 +246,18 @@ static inline brs_ext_result_t buffered_compress(
248
246
 
249
247
  static inline brs_ext_result_t buffered_compressor_finish(
250
248
  BrotliEncoderState* state_ptr,
251
- FILE* destination_file, uint8_t* destination_buffer, size_t* destination_length_ptr, size_t destination_buffer_length)
249
+ FILE* destination_file, brs_ext_byte_t* destination_buffer, size_t* destination_length_ptr, size_t destination_buffer_length)
252
250
  {
253
251
  BROTLI_BOOL result;
254
252
  brs_ext_result_t ext_result;
255
253
 
256
- const uint8_t* source = NULL;
257
- size_t source_length = 0;
254
+ const brs_ext_byte_t* source = NULL;
255
+ size_t source_length = 0;
258
256
 
259
257
  while (true) {
260
- uint8_t* remaining_destination_buffer = destination_buffer + *destination_length_ptr;
261
- size_t remaining_destination_buffer_length = destination_buffer_length - *destination_length_ptr;
262
- size_t prev_remaining_destination_buffer_length = remaining_destination_buffer_length;
258
+ brs_ext_byte_t* remaining_destination_buffer = destination_buffer + *destination_length_ptr;
259
+ size_t remaining_destination_buffer_length = destination_buffer_length - *destination_length_ptr;
260
+ size_t prev_remaining_destination_buffer_length = remaining_destination_buffer_length;
263
261
 
264
262
  result = BrotliEncoderCompressStream(
265
263
  state_ptr,
@@ -294,14 +292,14 @@ static inline brs_ext_result_t buffered_compressor_finish(
294
292
 
295
293
  static inline brs_ext_result_t compress(
296
294
  BrotliEncoderState* state_ptr,
297
- FILE* source_file, uint8_t* source_buffer, size_t source_buffer_length,
298
- FILE* destination_file, uint8_t* destination_buffer, size_t destination_buffer_length)
295
+ FILE* source_file, brs_ext_byte_t* source_buffer, size_t source_buffer_length,
296
+ FILE* destination_file, brs_ext_byte_t* destination_buffer, size_t destination_buffer_length)
299
297
  {
300
298
  brs_ext_result_t ext_result;
301
299
 
302
- const uint8_t* source = source_buffer;
303
- size_t source_length = 0;
304
- size_t destination_length = 0;
300
+ const brs_ext_byte_t* source = source_buffer;
301
+ size_t source_length = 0;
302
+ size_t destination_length = 0;
305
303
 
306
304
  BUFFERED_READ_SOURCE(
307
305
  buffered_compress,
@@ -347,8 +345,8 @@ VALUE brs_ext_compress_io(VALUE BRS_EXT_UNUSED(self), VALUE source, VALUE destin
347
345
  destination_buffer_length = BRS_DEFAULT_DESTINATION_BUFFER_LENGTH_FOR_COMPRESSOR;
348
346
  }
349
347
 
350
- uint8_t* source_buffer;
351
- uint8_t* destination_buffer;
348
+ brs_ext_byte_t* source_buffer;
349
+ brs_ext_byte_t* destination_buffer;
352
350
 
353
351
  ext_result = create_buffers(
354
352
  &source_buffer, source_buffer_length,
@@ -381,17 +379,17 @@ VALUE brs_ext_compress_io(VALUE BRS_EXT_UNUSED(self), VALUE source, VALUE destin
381
379
  // -- decompress --
382
380
 
383
381
  static inline brs_ext_result_t buffered_decompress(
384
- BrotliDecoderState* state_ptr,
385
- const uint8_t** source_ptr, size_t* source_length_ptr,
386
- FILE* destination_file, uint8_t* destination_buffer, size_t* destination_length_ptr, size_t destination_buffer_length)
382
+ BrotliDecoderState* state_ptr,
383
+ const brs_ext_byte_t** source_ptr, size_t* source_length_ptr,
384
+ FILE* destination_file, brs_ext_byte_t* destination_buffer, size_t* destination_length_ptr, size_t destination_buffer_length)
387
385
  {
388
386
  BrotliDecoderResult result;
389
387
  brs_ext_result_t ext_result;
390
388
 
391
389
  while (true) {
392
- uint8_t* remaining_destination_buffer = destination_buffer + *destination_length_ptr;
393
- size_t remaining_destination_buffer_length = destination_buffer_length - *destination_length_ptr;
394
- size_t prev_remaining_destination_buffer_length = remaining_destination_buffer_length;
390
+ brs_ext_byte_t* remaining_destination_buffer = destination_buffer + *destination_length_ptr;
391
+ size_t remaining_destination_buffer_length = destination_buffer_length - *destination_length_ptr;
392
+ size_t prev_remaining_destination_buffer_length = remaining_destination_buffer_length;
395
393
 
396
394
  result = BrotliDecoderDecompressStream(
397
395
  state_ptr,
@@ -429,14 +427,14 @@ static inline brs_ext_result_t buffered_decompress(
429
427
 
430
428
  static inline brs_ext_result_t decompress(
431
429
  BrotliDecoderState* state_ptr,
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)
430
+ FILE* source_file, brs_ext_byte_t* source_buffer, size_t source_buffer_length,
431
+ FILE* destination_file, brs_ext_byte_t* destination_buffer, size_t destination_buffer_length)
434
432
  {
435
433
  brs_ext_result_t ext_result;
436
434
 
437
- const uint8_t* source = source_buffer;
438
- size_t source_length = 0;
439
- size_t destination_length = 0;
435
+ const brs_ext_byte_t* source = source_buffer;
436
+ size_t source_length = 0;
437
+ size_t destination_length = 0;
440
438
 
441
439
  BUFFERED_READ_SOURCE(
442
440
  buffered_decompress,
@@ -474,8 +472,8 @@ VALUE brs_ext_decompress_io(VALUE BRS_EXT_UNUSED(self), VALUE source, VALUE dest
474
472
  destination_buffer_length = BRS_DEFAULT_DESTINATION_BUFFER_LENGTH_FOR_DECOMPRESSOR;
475
473
  }
476
474
 
477
- uint8_t* source_buffer;
478
- uint8_t* destination_buffer;
475
+ brs_ext_byte_t* source_buffer;
476
+ brs_ext_byte_t* destination_buffer;
479
477
 
480
478
  ext_result = create_buffers(
481
479
  &source_buffer, source_buffer_length,
@@ -2,7 +2,6 @@
2
2
  // Copyright (c) 2019 AUTHORS, MIT License.
3
3
 
4
4
  #include "brs_ext/buffer.h"
5
- #include "brs_ext/common.h"
6
5
  #include "brs_ext/io.h"
7
6
  #include "brs_ext/option.h"
8
7
  #include "brs_ext/stream/compressor.h"
@@ -5,10 +5,7 @@
5
5
 
6
6
  #include <brotli/decode.h>
7
7
  #include <brotli/encode.h>
8
- #include <stdbool.h>
9
- #include <stdlib.h>
10
8
 
11
- #include "brs_ext/common.h"
12
9
  #include "brs_ext/error.h"
13
10
  #include "ruby.h"
14
11
 
@@ -7,7 +7,6 @@
7
7
  #include <brotli/decode.h>
8
8
  #include <brotli/encode.h>
9
9
  #include <stdbool.h>
10
- #include <stdint.h>
11
10
  #include <stdlib.h>
12
11
 
13
12
  #include "brs_ext/common.h"
@@ -22,8 +21,8 @@ enum {
22
21
  BRS_EXT_OPTION_TYPE_MODE
23
22
  };
24
23
 
25
- typedef uint_fast8_t brs_ext_option_type_t;
26
- typedef uint32_t brs_ext_option_value_t;
24
+ typedef brs_ext_byte_fast_t brs_ext_option_type_t;
25
+ typedef uint32_t brs_ext_option_value_t;
27
26
 
28
27
  typedef struct {
29
28
  bool has_value;
@@ -5,11 +5,8 @@
5
5
 
6
6
  #include <brotli/encode.h>
7
7
  #include <brotli/types.h>
8
- #include <stdint.h>
9
- #include <stdlib.h>
10
8
 
11
9
  #include "brs_ext/buffer.h"
12
- #include "brs_ext/common.h"
13
10
  #include "brs_ext/error.h"
14
11
  #include "brs_ext/option.h"
15
12
  #include "ruby.h"
@@ -21,7 +18,7 @@ static void free_compressor(brs_ext_compressor_t* compressor_ptr)
21
18
  BrotliEncoderDestroyInstance(state_ptr);
22
19
  }
23
20
 
24
- uint8_t* destination_buffer = compressor_ptr->destination_buffer;
21
+ brs_ext_byte_t* destination_buffer = compressor_ptr->destination_buffer;
25
22
  if (destination_buffer != NULL) {
26
23
  free(destination_buffer);
27
24
  }
@@ -70,7 +67,7 @@ VALUE brs_ext_initialize_compressor(VALUE self, VALUE options)
70
67
  destination_buffer_length = BRS_DEFAULT_DESTINATION_BUFFER_LENGTH_FOR_COMPRESSOR;
71
68
  }
72
69
 
73
- uint8_t* destination_buffer = malloc(destination_buffer_length);
70
+ brs_ext_byte_t* destination_buffer = malloc(destination_buffer_length);
74
71
  if (destination_buffer == NULL) {
75
72
  BrotliEncoderDestroyInstance(state_ptr);
76
73
  brs_ext_raise_error(BRS_EXT_ERROR_ALLOCATE_FAILED);
@@ -90,13 +87,13 @@ VALUE brs_ext_initialize_compressor(VALUE self, VALUE options)
90
87
  brs_ext_raise_error(BRS_EXT_ERROR_USED_AFTER_CLOSE); \
91
88
  }
92
89
 
93
- #define GET_SOURCE_DATA(source_value) \
94
- Check_Type(source_value, T_STRING); \
95
- \
96
- const char* source = RSTRING_PTR(source_value); \
97
- size_t source_length = RSTRING_LEN(source_value); \
98
- const uint8_t* remaining_source = (const uint8_t*)source; \
99
- size_t remaining_source_length = source_length;
90
+ #define GET_SOURCE_DATA(source_value) \
91
+ Check_Type(source_value, T_STRING); \
92
+ \
93
+ const char* source = RSTRING_PTR(source_value); \
94
+ size_t source_length = RSTRING_LEN(source_value); \
95
+ const brs_ext_byte_t* remaining_source = (const brs_ext_byte_t*)source; \
96
+ size_t remaining_source_length = source_length;
100
97
 
101
98
  VALUE brs_ext_compress(VALUE self, VALUE source_value)
102
99
  {
@@ -130,8 +127,8 @@ VALUE brs_ext_flush_compressor(VALUE self)
130
127
 
131
128
  BrotliEncoderState* state_ptr = compressor_ptr->state_ptr;
132
129
 
133
- const uint8_t* remaining_source = NULL;
134
- size_t remaining_source_length = 0;
130
+ const brs_ext_byte_t* remaining_source = NULL;
131
+ size_t remaining_source_length = 0;
135
132
 
136
133
  BROTLI_BOOL result = BrotliEncoderCompressStream(
137
134
  state_ptr,
@@ -156,8 +153,8 @@ VALUE brs_ext_finish_compressor(VALUE self)
156
153
 
157
154
  BrotliEncoderState* state_ptr = compressor_ptr->state_ptr;
158
155
 
159
- const uint8_t* remaining_source = NULL;
160
- size_t remaining_source_length = 0;
156
+ const brs_ext_byte_t* remaining_source = NULL;
157
+ size_t remaining_source_length = 0;
161
158
 
162
159
  BROTLI_BOOL result = BrotliEncoderCompressStream(
163
160
  state_ptr,
@@ -180,9 +177,9 @@ VALUE brs_ext_compressor_read_result(VALUE self)
180
177
  GET_COMPRESSOR(self);
181
178
  DO_NOT_USE_AFTER_CLOSE(compressor_ptr);
182
179
 
183
- uint8_t* destination_buffer = compressor_ptr->destination_buffer;
184
- size_t destination_buffer_length = compressor_ptr->destination_buffer_length;
185
- size_t remaining_destination_buffer_length = compressor_ptr->remaining_destination_buffer_length;
180
+ brs_ext_byte_t* destination_buffer = compressor_ptr->destination_buffer;
181
+ size_t destination_buffer_length = compressor_ptr->destination_buffer_length;
182
+ size_t remaining_destination_buffer_length = compressor_ptr->remaining_destination_buffer_length;
186
183
 
187
184
  const char* result = (const char*)destination_buffer;
188
185
  size_t result_length = destination_buffer_length - remaining_destination_buffer_length;
@@ -207,7 +204,7 @@ VALUE brs_ext_compressor_close(VALUE self)
207
204
  compressor_ptr->state_ptr = NULL;
208
205
  }
209
206
 
210
- uint8_t* destination_buffer = compressor_ptr->destination_buffer;
207
+ brs_ext_byte_t* destination_buffer = compressor_ptr->destination_buffer;
211
208
  if (destination_buffer != NULL) {
212
209
  free(destination_buffer);
213
210
 
@@ -5,16 +5,16 @@
5
5
  #define BRS_EXT_STREAM_COMPRESSOR_H
6
6
 
7
7
  #include <brotli/encode.h>
8
- #include <stdint.h>
9
8
  #include <stdlib.h>
10
9
 
10
+ #include "brs_ext/common.h"
11
11
  #include "ruby.h"
12
12
 
13
13
  typedef struct {
14
14
  BrotliEncoderState* state_ptr;
15
- uint8_t* destination_buffer;
15
+ brs_ext_byte_t* destination_buffer;
16
16
  size_t destination_buffer_length;
17
- uint8_t* remaining_destination_buffer;
17
+ brs_ext_byte_t* remaining_destination_buffer;
18
18
  size_t remaining_destination_buffer_length;
19
19
  } brs_ext_compressor_t;
20
20
 
@@ -4,11 +4,8 @@
4
4
  #include "brs_ext/stream/decompressor.h"
5
5
 
6
6
  #include <brotli/decode.h>
7
- #include <stdint.h>
8
- #include <stdlib.h>
9
7
 
10
8
  #include "brs_ext/buffer.h"
11
- #include "brs_ext/common.h"
12
9
  #include "brs_ext/error.h"
13
10
  #include "brs_ext/option.h"
14
11
  #include "ruby.h"
@@ -20,7 +17,7 @@ static void free_decompressor(brs_ext_decompressor_t* decompressor_ptr)
20
17
  BrotliDecoderDestroyInstance(state_ptr);
21
18
  }
22
19
 
23
- uint8_t* destination_buffer = decompressor_ptr->destination_buffer;
20
+ brs_ext_byte_t* destination_buffer = decompressor_ptr->destination_buffer;
24
21
  if (destination_buffer != NULL) {
25
22
  free(destination_buffer);
26
23
  }
@@ -69,7 +66,7 @@ VALUE brs_ext_initialize_decompressor(VALUE self, VALUE options)
69
66
  destination_buffer_length = BRS_DEFAULT_DESTINATION_BUFFER_LENGTH_FOR_DECOMPRESSOR;
70
67
  }
71
68
 
72
- uint8_t* destination_buffer = malloc(destination_buffer_length);
69
+ brs_ext_byte_t* destination_buffer = malloc(destination_buffer_length);
73
70
  if (destination_buffer == NULL) {
74
71
  BrotliDecoderDestroyInstance(state_ptr);
75
72
  brs_ext_raise_error(BRS_EXT_ERROR_ALLOCATE_FAILED);
@@ -89,13 +86,13 @@ VALUE brs_ext_initialize_decompressor(VALUE self, VALUE options)
89
86
  brs_ext_raise_error(BRS_EXT_ERROR_USED_AFTER_CLOSE); \
90
87
  }
91
88
 
92
- #define GET_SOURCE_DATA(source_value) \
93
- Check_Type(source_value, T_STRING); \
94
- \
95
- const char* source = RSTRING_PTR(source_value); \
96
- size_t source_length = RSTRING_LEN(source_value); \
97
- const uint8_t* remaining_source = (const uint8_t*)source; \
98
- size_t remaining_source_length = source_length;
89
+ #define GET_SOURCE_DATA(source_value) \
90
+ Check_Type(source_value, T_STRING); \
91
+ \
92
+ const char* source = RSTRING_PTR(source_value); \
93
+ size_t source_length = RSTRING_LEN(source_value); \
94
+ const brs_ext_byte_t* remaining_source = (const brs_ext_byte_t*)source; \
95
+ size_t remaining_source_length = source_length;
99
96
 
100
97
  VALUE brs_ext_decompress(VALUE self, VALUE source_value)
101
98
  {
@@ -128,9 +125,9 @@ VALUE brs_ext_decompressor_read_result(VALUE self)
128
125
  GET_DECOMPRESSOR(self);
129
126
  DO_NOT_USE_AFTER_CLOSE(decompressor_ptr);
130
127
 
131
- uint8_t* destination_buffer = decompressor_ptr->destination_buffer;
132
- size_t destination_buffer_length = decompressor_ptr->destination_buffer_length;
133
- size_t remaining_destination_buffer_length = decompressor_ptr->remaining_destination_buffer_length;
128
+ brs_ext_byte_t* destination_buffer = decompressor_ptr->destination_buffer;
129
+ size_t destination_buffer_length = decompressor_ptr->destination_buffer_length;
130
+ size_t remaining_destination_buffer_length = decompressor_ptr->remaining_destination_buffer_length;
134
131
 
135
132
  const char* result = (const char*)destination_buffer;
136
133
  size_t result_length = destination_buffer_length - remaining_destination_buffer_length;
@@ -155,7 +152,7 @@ VALUE brs_ext_decompressor_close(VALUE self)
155
152
  decompressor_ptr->state_ptr = NULL;
156
153
  }
157
154
 
158
- uint8_t* destination_buffer = decompressor_ptr->destination_buffer;
155
+ brs_ext_byte_t* destination_buffer = decompressor_ptr->destination_buffer;
159
156
  if (destination_buffer != NULL) {
160
157
  free(destination_buffer);
161
158
 
@@ -5,16 +5,16 @@
5
5
  #define BRS_EXT_STREAM_DECOMPRESSOR_H
6
6
 
7
7
  #include <brotli/decode.h>
8
- #include <stdint.h>
9
8
  #include <stdlib.h>
10
9
 
10
+ #include "brs_ext/common.h"
11
11
  #include "ruby.h"
12
12
 
13
13
  typedef struct {
14
14
  BrotliDecoderState* state_ptr;
15
- uint8_t* destination_buffer;
15
+ brs_ext_byte_t* destination_buffer;
16
16
  size_t destination_buffer_length;
17
- uint8_t* remaining_destination_buffer;
17
+ brs_ext_byte_t* remaining_destination_buffer;
18
18
  size_t remaining_destination_buffer_length;
19
19
  } brs_ext_decompressor_t;
20
20
 
@@ -6,11 +6,9 @@
6
6
  #include <brotli/decode.h>
7
7
  #include <brotli/encode.h>
8
8
  #include <brotli/types.h>
9
- #include <stdint.h>
10
9
  #include <stdlib.h>
11
10
 
12
11
  #include "brs_ext/buffer.h"
13
- #include "brs_ext/common.h"
14
12
  #include "brs_ext/error.h"
15
13
  #include "brs_ext/macro.h"
16
14
  #include "brs_ext/option.h"
@@ -57,15 +55,15 @@ static inline brs_ext_result_t compress(
57
55
  BROTLI_BOOL result;
58
56
  brs_ext_result_t ext_result;
59
57
 
60
- const uint8_t* remaining_source = (const uint8_t*)source;
61
- size_t remaining_source_length = source_length;
58
+ const brs_ext_byte_t* remaining_source = (const brs_ext_byte_t*)source;
59
+ size_t remaining_source_length = source_length;
62
60
 
63
61
  size_t destination_length = 0;
64
62
  size_t remaining_destination_buffer_length = destination_buffer_length;
65
63
 
66
64
  while (true) {
67
- uint8_t* remaining_destination_buffer = (uint8_t*)RSTRING_PTR(destination_value) + destination_length;
68
- size_t prev_remaining_destination_buffer_length = remaining_destination_buffer_length;
65
+ brs_ext_byte_t* remaining_destination_buffer = (brs_ext_byte_t*)RSTRING_PTR(destination_value) + destination_length;
66
+ size_t prev_remaining_destination_buffer_length = remaining_destination_buffer_length;
69
67
 
70
68
  result = BrotliEncoderCompressStream(
71
69
  state_ptr,
@@ -159,15 +157,15 @@ static inline brs_ext_result_t decompress(
159
157
  BrotliDecoderResult result;
160
158
  brs_ext_result_t ext_result;
161
159
 
162
- const uint8_t* remaining_source = (const uint8_t*)source;
163
- size_t remaining_source_length = source_length;
160
+ const brs_ext_byte_t* remaining_source = (const brs_ext_byte_t*)source;
161
+ size_t remaining_source_length = source_length;
164
162
 
165
163
  size_t destination_length = 0;
166
164
  size_t remaining_destination_buffer_length = destination_buffer_length;
167
165
 
168
166
  while (true) {
169
- uint8_t* remaining_destination_buffer = (uint8_t*)RSTRING_PTR(destination_value) + destination_length;
170
- size_t prev_remaining_destination_buffer_length = remaining_destination_buffer_length;
167
+ brs_ext_byte_t* remaining_destination_buffer = (brs_ext_byte_t*)RSTRING_PTR(destination_value) + destination_length;
168
+ size_t prev_remaining_destination_buffer_length = remaining_destination_buffer_length;
171
169
 
172
170
  result = BrotliDecoderDecompressStream(
173
171
  state_ptr,
@@ -23,17 +23,18 @@ module BRS
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 BRS
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 BRS
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 BRS
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 BRS
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 BRS
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 BRS
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
@@ -26,7 +39,7 @@ module BRS
26
39
  end
27
40
 
28
41
  def self.validate_io(value)
29
- raise ValidateError, "invalid io" unless value.is_a? ::IO
42
+ raise ValidateError, "invalid io" unless IO_METHODS.all? { |method| value.respond_to? method }
30
43
  end
31
44
 
32
45
  def self.validate_hash(value)
@@ -2,5 +2,5 @@
2
2
  # Copyright (c) 2019 AUTHORS, MIT License.
3
3
 
4
4
  module BRS
5
- VERSION = "1.1.1".freeze
5
+ VERSION = "1.1.2".freeze
6
6
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-brs
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1
4
+ version: 1.1.2
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
@@ -214,7 +214,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
214
214
  - !ruby/object:Gem::Version
215
215
  version: '0'
216
216
  requirements: []
217
- rubygems_version: 3.0.6
217
+ rubygems_version: 3.1.2
218
218
  signing_key:
219
219
  specification_version: 4
220
220
  summary: Ruby bindings for brotli library.