ruby-lzws 1.1.3 → 1.1.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 68638ae503703523496d753cb9c343dcfd258eb0a1cbf2da1c4fa0888df53d05
4
- data.tar.gz: cdbfd18419ca03bb13c3db8908b5afed42500ff40d45bd412191fca723b3e51b
3
+ metadata.gz: 6fc8861bd91fe484c375cdeae3ad55e478727e8a1314117fb3897cef408bd401
4
+ data.tar.gz: 9b7a0d9cd62930a12250641599638d80abb34737bae20842109d91f1dfee84a8
5
5
  SHA512:
6
- metadata.gz: bfa3497c91ca513e97a82d540d3302cb330d7addadda117eab1fe3f7d615bbb774f3bf00f037c8cb4dcd0f2abb9ec92e240459eca7fab5f9689307f70130c38c
7
- data.tar.gz: beef34ff8bdf2f20ab9ab9dcd797a7587d4d74c79e82dea0eff3aa64cd11e1222eefab566a6d45baa6e9ee34427ca8dcfd46ab6769bedc44a6758d2276527627
6
+ metadata.gz: 880eb17f48cca872b77a56936aedebe4aa416eb971e51743550e0bd02c473568fb638d412deab64c522fa84895732c9f91da338a7d4f79bd3ac4c382f35326eb
7
+ data.tar.gz: e29e72c646f05e55ec4411a06e4be7122581962d9fe46164bc6bbaeefd1e874595ad74783503f76bf049096730043032976c8595e2d7903d9acb3ab9bb39b8cc
data/README.md CHANGED
@@ -186,7 +186,7 @@ File maintains both source and destination buffers, it accepts both `source_buff
186
186
 
187
187
  ## Stream::Writer
188
188
 
189
- Its behaviour is similar to builtin [`Zlib::GzipWriter`](https://ruby-doc.org/stdlib-2.6.1/libdoc/zlib/rdoc/Zlib/GzipWriter.html).
189
+ Its behaviour is similar to builtin [`Zlib::GzipWriter`](https://ruby-doc.org/stdlib-2.7.0/libdoc/zlib/rdoc/Zlib/GzipWriter.html).
190
190
 
191
191
  Writer maintains destination buffer only, so it accepts `destination_buffer_length` option only.
192
192
 
@@ -220,7 +220,7 @@ Set another encodings, `nil` is just for compatibility with `IO`.
220
220
  #tell
221
221
  ```
222
222
 
223
- See [`IO`](https://ruby-doc.org/core-2.6.1/IO.html) docs.
223
+ See [`IO`](https://ruby-doc.org/core-2.7.0/IO.html) docs.
224
224
 
225
225
  ```
226
226
  #write(*objects)
@@ -230,7 +230,7 @@ See [`IO`](https://ruby-doc.org/core-2.6.1/IO.html) docs.
230
230
  #closed?
231
231
  ```
232
232
 
233
- See [`Zlib::GzipWriter`](https://ruby-doc.org/stdlib-2.6.1/libdoc/zlib/rdoc/Zlib/GzipWriter.html) docs.
233
+ See [`Zlib::GzipWriter`](https://ruby-doc.org/stdlib-2.7.0/libdoc/zlib/rdoc/Zlib/GzipWriter.html) docs.
234
234
 
235
235
  ```
236
236
  #write_nonblock(object, *options)
@@ -252,11 +252,11 @@ Behaviour is the same as `IO#write_nonblock` method.
252
252
  #puts(*objects)
253
253
  ```
254
254
 
255
- Typical helpers, see [`Zlib::GzipWriter`](https://ruby-doc.org/stdlib-2.6.1/libdoc/zlib/rdoc/Zlib/GzipWriter.html) docs.
255
+ Typical helpers, see [`Zlib::GzipWriter`](https://ruby-doc.org/stdlib-2.7.0/libdoc/zlib/rdoc/Zlib/GzipWriter.html) docs.
256
256
 
257
257
  ## Stream::Reader
258
258
 
259
- Its behaviour is similar to builtin [`Zlib::GzipReader`](https://ruby-doc.org/stdlib-2.6.1/libdoc/zlib/rdoc/Zlib/GzipReader.html).
259
+ Its behaviour is similar to builtin [`Zlib::GzipReader`](https://ruby-doc.org/stdlib-2.7.0/libdoc/zlib/rdoc/Zlib/GzipReader.html).
260
260
 
261
261
  Reader maintains both source and destination buffers, it accepts both `source_buffer_length` and `destination_buffer_length` options.
262
262
 
@@ -291,7 +291,7 @@ Set another encodings.
291
291
  #tell
292
292
  ```
293
293
 
294
- See [`IO`](https://ruby-doc.org/core-2.6.1/IO.html) docs.
294
+ See [`IO`](https://ruby-doc.org/core-2.7.0/IO.html) docs.
295
295
 
296
296
  ```
297
297
  #read(bytes_to_read = nil, out_buffer = nil)
@@ -301,14 +301,14 @@ See [`IO`](https://ruby-doc.org/core-2.6.1/IO.html) docs.
301
301
  #closed?
302
302
  ```
303
303
 
304
- See [`Zlib::GzipReader`](https://ruby-doc.org/stdlib-2.6.1/libdoc/zlib/rdoc/Zlib/GzipReader.html) docs.
304
+ See [`Zlib::GzipReader`](https://ruby-doc.org/stdlib-2.7.0/libdoc/zlib/rdoc/Zlib/GzipReader.html) docs.
305
305
 
306
306
  ```
307
307
  #readpartial(bytes_to_read = nil, out_buffer = nil)
308
308
  #read_nonblock(bytes_to_read, out_buffer = nil, *options)
309
309
  ```
310
310
 
311
- See [`IO`](https://ruby-doc.org/core-2.6.1/IO.html) docs.
311
+ See [`IO`](https://ruby-doc.org/core-2.7.0/IO.html) docs.
312
312
 
313
313
  ```
314
314
  #getbyte
@@ -331,13 +331,15 @@ See [`IO`](https://ruby-doc.org/core-2.6.1/IO.html) docs.
331
331
  #ungetline(line)
332
332
  ```
333
333
 
334
- Typical helpers, see [`Zlib::GzipReader`](https://ruby-doc.org/stdlib-2.6.1/libdoc/zlib/rdoc/Zlib/GzipReader.html) docs.
334
+ Typical helpers, see [`Zlib::GzipReader`](https://ruby-doc.org/stdlib-2.7.0/libdoc/zlib/rdoc/Zlib/GzipReader.html) docs.
335
335
 
336
336
  ## CI
337
337
 
338
- Travis and Appveyor CI uses [scripts/ci_test.sh](scripts/ci_test.sh) directly.
339
- Cirrus and Circle CI uses prebuilt [scripts/test-images](scripts/test-images).
340
- Cirrus CI uses amd64 image, Circle CI - i686.
338
+ See universal test script [scripts/ci_test.sh](scripts/ci_test.sh) for CI.
339
+ Please visit [scripts/test-images](scripts/test-images).
340
+ You can run this test script using many native and cross images.
341
+
342
+ Cirrus CI uses `x86_64-pc-linux-gnu` image, Circle CI - `x86_64-gentoo-linux-musl` image.
341
343
 
342
344
  ## License
343
345
 
@@ -10,4 +10,7 @@
10
10
 
11
11
  typedef uint_fast8_t lzws_ext_result_t;
12
12
 
13
+ typedef uint8_t lzws_ext_byte_t;
14
+ typedef uint_fast8_t lzws_ext_byte_fast_t;
15
+
13
16
  #endif // LZWS_EXT_COMMON_H
@@ -3,7 +3,6 @@
3
3
 
4
4
  #include "lzws_ext/error.h"
5
5
 
6
- #include "lzws_ext/common.h"
7
6
  #include "ruby.h"
8
7
 
9
8
  static inline NORETURN(void raise(const char* name, const char* description))
@@ -6,7 +6,6 @@
6
6
  #include <lzws/common.h>
7
7
  #include <lzws/file.h>
8
8
 
9
- #include "lzws_ext/common.h"
10
9
  #include "lzws_ext/error.h"
11
10
  #include "lzws_ext/io.h"
12
11
  #include "lzws_ext/macro.h"
@@ -2,7 +2,6 @@
2
2
  // Copyright (c) 2019 AUTHORS, MIT License.
3
3
 
4
4
  #include "lzws_ext/buffer.h"
5
- #include "lzws_ext/common.h"
6
5
  #include "lzws_ext/io.h"
7
6
  #include "lzws_ext/stream/compressor.h"
8
7
  #include "lzws_ext/stream/decompressor.h"
@@ -3,9 +3,6 @@
3
3
 
4
4
  #include "lzws_ext/option.h"
5
5
 
6
- #include <stdbool.h>
7
- #include <stdlib.h>
8
-
9
6
  #include "lzws_ext/error.h"
10
7
  #include "ruby.h"
11
8
 
@@ -7,6 +7,7 @@
7
7
  #include <stdbool.h>
8
8
  #include <stdlib.h>
9
9
 
10
+ #include "lzws_ext/common.h"
10
11
  #include "ruby.h"
11
12
 
12
13
  bool lzws_ext_get_bool_option_value(VALUE options, const char* name);
@@ -22,12 +23,12 @@ size_t lzws_ext_get_size_option_value(VALUE options, const char* name);
22
23
  #define LZWS_EXT_GET_SIZE_OPTION(options, name) \
23
24
  size_t name = lzws_ext_get_size_option_value(options, #name);
24
25
 
25
- #define LZWS_EXT_GET_COMPRESSOR_OPTIONS(options) \
26
- LZWS_EXT_GET_BOOL_OPTION(options, without_magic_header); \
27
- LZWS_EXT_GET_UINT_OPTION(options, uint_fast8_t, max_code_bit_length); \
28
- LZWS_EXT_GET_BOOL_OPTION(options, block_mode); \
29
- LZWS_EXT_GET_BOOL_OPTION(options, msb); \
30
- LZWS_EXT_GET_BOOL_OPTION(options, unaligned_bit_groups); \
26
+ #define LZWS_EXT_GET_COMPRESSOR_OPTIONS(options) \
27
+ LZWS_EXT_GET_BOOL_OPTION(options, without_magic_header); \
28
+ LZWS_EXT_GET_UINT_OPTION(options, lzws_ext_byte_fast_t, max_code_bit_length); \
29
+ LZWS_EXT_GET_BOOL_OPTION(options, block_mode); \
30
+ LZWS_EXT_GET_BOOL_OPTION(options, msb); \
31
+ LZWS_EXT_GET_BOOL_OPTION(options, unaligned_bit_groups); \
31
32
  LZWS_EXT_GET_BOOL_OPTION(options, quiet);
32
33
 
33
34
  #define LZWS_EXT_GET_DECOMPRESSOR_OPTIONS(options) \
@@ -8,8 +8,6 @@
8
8
  #include <lzws/compressor/common.h>
9
9
  #include <lzws/compressor/main.h>
10
10
  #include <lzws/compressor/state.h>
11
- #include <stdint.h>
12
- #include <stdlib.h>
13
11
 
14
12
  #include "lzws_ext/error.h"
15
13
  #include "lzws_ext/option.h"
@@ -22,7 +20,7 @@ static void free_compressor(lzws_ext_compressor_t* compressor_ptr)
22
20
  lzws_compressor_free_state(state_ptr);
23
21
  }
24
22
 
25
- uint8_t* destination_buffer = compressor_ptr->destination_buffer;
23
+ lzws_ext_byte_t* destination_buffer = compressor_ptr->destination_buffer;
26
24
  if (destination_buffer != NULL) {
27
25
  free(destination_buffer);
28
26
  }
@@ -73,7 +71,7 @@ VALUE lzws_ext_initialize_compressor(VALUE self, VALUE options)
73
71
  }
74
72
  }
75
73
 
76
- uint8_t* destination_buffer;
74
+ lzws_ext_byte_t* destination_buffer;
77
75
 
78
76
  result = lzws_create_destination_buffer_for_compressor(&destination_buffer, &destination_buffer_length, quiet);
79
77
  if (result != 0) {
@@ -95,13 +93,13 @@ VALUE lzws_ext_initialize_compressor(VALUE self, VALUE options)
95
93
  lzws_ext_raise_error(LZWS_EXT_ERROR_USED_AFTER_CLOSE); \
96
94
  }
97
95
 
98
- #define GET_SOURCE_DATA(source_value) \
99
- Check_Type(source_value, T_STRING); \
100
- \
101
- const char* source = RSTRING_PTR(source_value); \
102
- size_t source_length = RSTRING_LEN(source_value); \
103
- uint8_t* remaining_source = (uint8_t*)source; \
104
- size_t remaining_source_length = source_length;
96
+ #define GET_SOURCE_DATA(source_value) \
97
+ Check_Type(source_value, T_STRING); \
98
+ \
99
+ const char* source = RSTRING_PTR(source_value); \
100
+ size_t source_length = RSTRING_LEN(source_value); \
101
+ lzws_ext_byte_t* remaining_source = (lzws_ext_byte_t*)source; \
102
+ size_t remaining_source_length = source_length;
105
103
 
106
104
  VALUE lzws_ext_compress(VALUE self, VALUE source_value)
107
105
  {
@@ -151,9 +149,9 @@ VALUE lzws_ext_compressor_read_result(VALUE self)
151
149
  GET_COMPRESSOR(self);
152
150
  DO_NOT_USE_AFTER_CLOSE(compressor_ptr);
153
151
 
154
- uint8_t* destination_buffer = compressor_ptr->destination_buffer;
155
- size_t destination_buffer_length = compressor_ptr->destination_buffer_length;
156
- size_t remaining_destination_buffer_length = compressor_ptr->remaining_destination_buffer_length;
152
+ lzws_ext_byte_t* destination_buffer = compressor_ptr->destination_buffer;
153
+ size_t destination_buffer_length = compressor_ptr->destination_buffer_length;
154
+ size_t remaining_destination_buffer_length = compressor_ptr->remaining_destination_buffer_length;
157
155
 
158
156
  const char* result = (const char*)destination_buffer;
159
157
  size_t result_length = destination_buffer_length - remaining_destination_buffer_length;
@@ -178,7 +176,7 @@ VALUE lzws_ext_compressor_close(VALUE self)
178
176
  compressor_ptr->state_ptr = NULL;
179
177
  }
180
178
 
181
- uint8_t* destination_buffer = compressor_ptr->destination_buffer;
179
+ lzws_ext_byte_t* destination_buffer = compressor_ptr->destination_buffer;
182
180
  if (destination_buffer != NULL) {
183
181
  free(destination_buffer);
184
182
 
@@ -5,16 +5,16 @@
5
5
  #define LZWS_EXT_STREAM_COMPRESSOR_H
6
6
 
7
7
  #include <lzws/compressor/state.h>
8
- #include <stdint.h>
9
8
  #include <stdlib.h>
10
9
 
10
+ #include "lzws_ext/common.h"
11
11
  #include "ruby.h"
12
12
 
13
13
  typedef struct {
14
14
  lzws_compressor_state_t* state_ptr;
15
- uint8_t* destination_buffer;
15
+ lzws_ext_byte_t* destination_buffer;
16
16
  size_t destination_buffer_length;
17
- uint8_t* remaining_destination_buffer;
17
+ lzws_ext_byte_t* remaining_destination_buffer;
18
18
  size_t remaining_destination_buffer_length;
19
19
  } lzws_ext_compressor_t;
20
20
 
@@ -8,8 +8,6 @@
8
8
  #include <lzws/decompressor/common.h>
9
9
  #include <lzws/decompressor/main.h>
10
10
  #include <lzws/decompressor/state.h>
11
- #include <stdint.h>
12
- #include <stdlib.h>
13
11
 
14
12
  #include "lzws_ext/error.h"
15
13
  #include "lzws_ext/option.h"
@@ -22,7 +20,7 @@ static void free_decompressor(lzws_ext_decompressor_t* decompressor_ptr)
22
20
  lzws_decompressor_free_state(state_ptr);
23
21
  }
24
22
 
25
- uint8_t* destination_buffer = decompressor_ptr->destination_buffer;
23
+ lzws_ext_byte_t* destination_buffer = decompressor_ptr->destination_buffer;
26
24
  if (destination_buffer != NULL) {
27
25
  free(destination_buffer);
28
26
  }
@@ -71,7 +69,7 @@ VALUE lzws_ext_initialize_decompressor(VALUE self, VALUE options)
71
69
  }
72
70
  }
73
71
 
74
- uint8_t* destination_buffer;
72
+ lzws_ext_byte_t* destination_buffer;
75
73
 
76
74
  result = lzws_create_destination_buffer_for_decompressor(&destination_buffer, &destination_buffer_length, quiet);
77
75
  if (result != 0) {
@@ -93,13 +91,13 @@ VALUE lzws_ext_initialize_decompressor(VALUE self, VALUE options)
93
91
  lzws_ext_raise_error(LZWS_EXT_ERROR_USED_AFTER_CLOSE); \
94
92
  }
95
93
 
96
- #define GET_SOURCE_DATA(source_value) \
97
- Check_Type(source_value, T_STRING); \
98
- \
99
- const char* source = RSTRING_PTR(source_value); \
100
- size_t source_length = RSTRING_LEN(source_value); \
101
- uint8_t* remaining_source = (uint8_t*)source; \
102
- size_t remaining_source_length = source_length;
94
+ #define GET_SOURCE_DATA(source_value) \
95
+ Check_Type(source_value, T_STRING); \
96
+ \
97
+ const char* source = RSTRING_PTR(source_value); \
98
+ size_t source_length = RSTRING_LEN(source_value); \
99
+ lzws_ext_byte_t* remaining_source = (lzws_ext_byte_t*)source; \
100
+ size_t remaining_source_length = source_length;
103
101
 
104
102
  VALUE lzws_ext_decompress(VALUE self, VALUE source_value)
105
103
  {
@@ -137,9 +135,9 @@ VALUE lzws_ext_decompressor_read_result(VALUE self)
137
135
  GET_DECOMPRESSOR(self);
138
136
  DO_NOT_USE_AFTER_CLOSE(decompressor_ptr);
139
137
 
140
- uint8_t* destination_buffer = decompressor_ptr->destination_buffer;
141
- size_t destination_buffer_length = decompressor_ptr->destination_buffer_length;
142
- size_t remaining_destination_buffer_length = decompressor_ptr->remaining_destination_buffer_length;
138
+ lzws_ext_byte_t* destination_buffer = decompressor_ptr->destination_buffer;
139
+ size_t destination_buffer_length = decompressor_ptr->destination_buffer_length;
140
+ size_t remaining_destination_buffer_length = decompressor_ptr->remaining_destination_buffer_length;
143
141
 
144
142
  const char* result = (const char*)destination_buffer;
145
143
  size_t result_length = destination_buffer_length - remaining_destination_buffer_length;
@@ -164,7 +162,7 @@ VALUE lzws_ext_decompressor_close(VALUE self)
164
162
  decompressor_ptr->state_ptr = NULL;
165
163
  }
166
164
 
167
- uint8_t* destination_buffer = decompressor_ptr->destination_buffer;
165
+ lzws_ext_byte_t* destination_buffer = decompressor_ptr->destination_buffer;
168
166
  if (destination_buffer != NULL) {
169
167
  free(destination_buffer);
170
168
 
@@ -5,16 +5,16 @@
5
5
  #define LZWS_EXT_STREAM_DECOMPRESSOR_H
6
6
 
7
7
  #include <lzws/decompressor/state.h>
8
- #include <stdint.h>
9
8
  #include <stdlib.h>
10
9
 
10
+ #include "lzws_ext/common.h"
11
11
  #include "ruby.h"
12
12
 
13
13
  typedef struct {
14
14
  lzws_decompressor_state_t* state_ptr;
15
- uint8_t* destination_buffer;
15
+ lzws_ext_byte_t* destination_buffer;
16
16
  size_t destination_buffer_length;
17
- uint8_t* remaining_destination_buffer;
17
+ lzws_ext_byte_t* remaining_destination_buffer;
18
18
  size_t remaining_destination_buffer_length;
19
19
  } lzws_ext_decompressor_t;
20
20
 
@@ -11,7 +11,6 @@
11
11
  #include <lzws/decompressor/common.h>
12
12
  #include <lzws/decompressor/main.h>
13
13
  #include <lzws/decompressor/state.h>
14
- #include <stdint.h>
15
14
  #include <stdlib.h>
16
15
 
17
16
  #include "lzws_ext/buffer.h"
@@ -53,34 +52,34 @@ static inline lzws_ext_result_t increase_destination_buffer(
53
52
 
54
53
  // -- compress --
55
54
 
56
- #define BUFFERED_COMPRESS(function, ...) \
57
- while (true) { \
58
- uint8_t* remaining_destination_buffer = (uint8_t*)RSTRING_PTR(destination_value) + destination_length; \
59
- size_t prev_remaining_destination_buffer_length = remaining_destination_buffer_length; \
60
- \
61
- result = function(__VA_ARGS__, &remaining_destination_buffer, &remaining_destination_buffer_length); \
62
- \
63
- if ( \
64
- result != 0 && \
65
- result != LZWS_COMPRESSOR_NEEDS_MORE_DESTINATION) { \
66
- return LZWS_EXT_ERROR_UNEXPECTED; \
67
- } \
68
- \
69
- destination_length += prev_remaining_destination_buffer_length - remaining_destination_buffer_length; \
70
- \
71
- if (result == LZWS_COMPRESSOR_NEEDS_MORE_DESTINATION) { \
72
- ext_result = increase_destination_buffer( \
73
- destination_value, destination_length, \
74
- &remaining_destination_buffer_length, destination_buffer_length); \
75
- \
76
- if (ext_result != 0) { \
77
- return ext_result; \
78
- } \
79
- \
80
- continue; \
81
- } \
82
- \
83
- break; \
55
+ #define BUFFERED_COMPRESS(function, ...) \
56
+ while (true) { \
57
+ lzws_ext_byte_t* remaining_destination_buffer = (lzws_ext_byte_t*)RSTRING_PTR(destination_value) + destination_length; \
58
+ size_t prev_remaining_destination_buffer_length = remaining_destination_buffer_length; \
59
+ \
60
+ result = function(__VA_ARGS__, &remaining_destination_buffer, &remaining_destination_buffer_length); \
61
+ \
62
+ if ( \
63
+ result != 0 && \
64
+ result != LZWS_COMPRESSOR_NEEDS_MORE_DESTINATION) { \
65
+ return LZWS_EXT_ERROR_UNEXPECTED; \
66
+ } \
67
+ \
68
+ destination_length += prev_remaining_destination_buffer_length - remaining_destination_buffer_length; \
69
+ \
70
+ if (result == LZWS_COMPRESSOR_NEEDS_MORE_DESTINATION) { \
71
+ ext_result = increase_destination_buffer( \
72
+ destination_value, destination_length, \
73
+ &remaining_destination_buffer_length, destination_buffer_length); \
74
+ \
75
+ if (ext_result != 0) { \
76
+ return ext_result; \
77
+ } \
78
+ \
79
+ continue; \
80
+ } \
81
+ \
82
+ break; \
84
83
  }
85
84
 
86
85
  static inline lzws_ext_result_t compress(
@@ -91,8 +90,8 @@ static inline lzws_ext_result_t compress(
91
90
  lzws_result_t result;
92
91
  lzws_ext_result_t ext_result;
93
92
 
94
- uint8_t* remaining_source = (uint8_t*)source;
95
- size_t remaining_source_length = source_length;
93
+ lzws_ext_byte_t* remaining_source = (lzws_ext_byte_t*)source;
94
+ size_t remaining_source_length = source_length;
96
95
 
97
96
  size_t destination_length = 0;
98
97
  size_t remaining_destination_buffer_length = destination_buffer_length;
@@ -170,15 +169,15 @@ static inline lzws_ext_result_t decompress(
170
169
  lzws_result_t result;
171
170
  lzws_ext_result_t ext_result;
172
171
 
173
- uint8_t* remaining_source = (uint8_t*)source;
174
- size_t remaining_source_length = source_length;
172
+ lzws_ext_byte_t* remaining_source = (lzws_ext_byte_t*)source;
173
+ size_t remaining_source_length = source_length;
175
174
 
176
175
  size_t destination_length = 0;
177
176
  size_t remaining_destination_buffer_length = destination_buffer_length;
178
177
 
179
178
  while (true) {
180
- uint8_t* remaining_destination_buffer = (uint8_t*)RSTRING_PTR(destination_value) + destination_length;
181
- size_t prev_remaining_destination_buffer_length = remaining_destination_buffer_length;
179
+ lzws_ext_byte_t* remaining_destination_buffer = (lzws_ext_byte_t*)RSTRING_PTR(destination_value) + destination_length;
180
+ size_t prev_remaining_destination_buffer_length = remaining_destination_buffer_length;
182
181
 
183
182
  result = lzws_decompress(
184
183
  state_ptr,
@@ -23,17 +23,18 @@ module LZWS
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 LZWS
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 LZWS
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 LZWS
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 LZWS
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 LZWS
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 LZWS
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
@@ -22,7 +35,7 @@ module LZWS
22
35
  end
23
36
 
24
37
  def self.validate_io(value)
25
- raise ValidateError, "invalid io" unless value.is_a? ::IO
38
+ raise ValidateError, "invalid io" unless IO_METHODS.all? { |method| value.respond_to? method }
26
39
  end
27
40
 
28
41
  def self.validate_hash(value)
@@ -2,5 +2,5 @@
2
2
  # Copyright (c) 2019 AUTHORS, MIT License.
3
3
 
4
4
  module LZWS
5
- VERSION = "1.1.3".freeze
5
+ VERSION = "1.1.4".freeze
6
6
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-lzws
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.3
4
+ version: 1.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Aladjev
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-12-30 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 lzws library.