ruby-lzws 1.1.3 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +55 -65
- data/ext/extconf.rb +9 -2
- data/ext/lzws_ext/buffer.c +18 -4
- data/ext/lzws_ext/common.h +3 -0
- data/ext/lzws_ext/error.c +0 -1
- data/ext/lzws_ext/error.h +2 -1
- data/ext/lzws_ext/io.c +4 -10
- data/ext/lzws_ext/main.c +2 -1
- data/ext/lzws_ext/option.c +22 -7
- data/ext/lzws_ext/option.h +28 -23
- data/ext/lzws_ext/stream/compressor.c +29 -39
- data/ext/lzws_ext/stream/compressor.h +5 -4
- data/ext/lzws_ext/stream/decompressor.c +24 -31
- data/ext/lzws_ext/stream/decompressor.h +5 -4
- data/ext/lzws_ext/string.c +60 -75
- data/lib/lzws/file.rb +4 -0
- data/lib/lzws/option.rb +32 -33
- data/lib/lzws/stream/abstract.rb +9 -12
- data/lib/lzws/stream/raw/abstract.rb +4 -2
- data/lib/lzws/stream/raw/compressor.rb +2 -4
- data/lib/lzws/stream/raw/decompressor.rb +1 -3
- data/lib/lzws/stream/reader.rb +71 -52
- data/lib/lzws/stream/writer.rb +10 -5
- data/lib/lzws/stream/writer_helpers.rb +6 -5
- data/lib/lzws/validation.rb +15 -2
- data/lib/lzws/version.rb +1 -1
- metadata +10 -24
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 62d885a3a75f291ea4b808da4ef4e47a68574e74dae8fe39aad61d228a62643c
|
4
|
+
data.tar.gz: 90e5fc29ea554392dcf93bb391a38361707c14306099b6654765e399d111ea9d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 66c07c08d7094be0e9f2d802c01796529e0c14bcde067752aa629d7e3337218e0d6a08e7cfe08725659097fb0e3be90e7565a872a3c79dc96813afa6b235e4ab
|
7
|
+
data.tar.gz: a1d74a3408881c23f816818931685ec084bd2a0e9c114be212f8a059e37af8da882e9235f3780524e5e67557b3c9945f33b3ecab8535768e4737e972fc724d87
|
data/README.md
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
# Ruby bindings for lzws library
|
2
2
|
|
3
|
-
| Travis | AppVeyor |
|
4
|
-
| :---: | :---: | :---: | :---:
|
5
|
-
| [![Travis test status](https://travis-ci.com/andrew-aladev/ruby-lzws.svg?branch=master)](https://travis-ci.com/andrew-aladev/ruby-lzws) | [![AppVeyor test status](https://ci.appveyor.com/api/projects/status/github/andrew-aladev/ruby-lzws?branch=master&svg=true)](https://ci.appveyor.com/project/andrew-aladev/ruby-lzws/branch/master) | [![
|
3
|
+
| Travis | AppVeyor | Circle | Codecov |
|
4
|
+
| :---: | :---: | :---: | :---: |
|
5
|
+
| [![Travis test status](https://travis-ci.com/andrew-aladev/ruby-lzws.svg?branch=master)](https://travis-ci.com/andrew-aladev/ruby-lzws) | [![AppVeyor test status](https://ci.appveyor.com/api/projects/status/github/andrew-aladev/ruby-lzws?branch=master&svg=true)](https://ci.appveyor.com/project/andrew-aladev/ruby-lzws/branch/master) | [![Circle test status](https://circleci.com/gh/andrew-aladev/ruby-lzws/tree/master.svg?style=shield)](https://circleci.com/gh/andrew-aladev/ruby-lzws/tree/master) | [![Codecov](https://codecov.io/gh/andrew-aladev/ruby-lzws/branch/master/graph/badge.svg)](https://codecov.io/gh/andrew-aladev/ruby-lzws) |
|
6
6
|
|
7
7
|
See [lzws library](https://github.com/andrew-aladev/lzws).
|
8
8
|
|
9
9
|
## Installation
|
10
10
|
|
11
|
-
Please install lzws library first, use latest 1.
|
11
|
+
Please install lzws library first, use latest 1.4.0+ version.
|
12
12
|
|
13
13
|
```sh
|
14
14
|
gem install ruby-lzws
|
@@ -21,6 +21,8 @@ rake gem
|
|
21
21
|
gem install pkg/ruby-lzws-*.gem
|
22
22
|
```
|
23
23
|
|
24
|
+
You can also use [overlay](https://github.com/andrew-aladev/overlay) for gentoo.
|
25
|
+
|
24
26
|
## Usage
|
25
27
|
|
26
28
|
There are simple APIs: `String` and `File`. Also you can use generic streaming API: `Stream::Writer` and `Stream::Reader`.
|
@@ -36,6 +38,27 @@ LZWS::File.decompress "file.txt.Z", "file.txt"
|
|
36
38
|
|
37
39
|
LZWS::Stream::Writer.open("file.txt.Z") { |writer| writer << "TOBEORNOTTOBEORTOBEORNOT" }
|
38
40
|
puts LZWS::Stream::Reader.open("file.txt.Z") { |reader| reader.read }
|
41
|
+
|
42
|
+
writer = LZWS::Stream::Writer.new output_socket
|
43
|
+
begin
|
44
|
+
bytes_written = writer.write_nonblock "TOBEORNOTTOBEORTOBEORNOT"
|
45
|
+
# handle "bytes_written"
|
46
|
+
rescue IO::WaitWritable
|
47
|
+
# handle wait
|
48
|
+
ensure
|
49
|
+
writer.close
|
50
|
+
end
|
51
|
+
|
52
|
+
reader = LZWS::Stream::Reader.new input_socket
|
53
|
+
begin
|
54
|
+
puts reader.read_nonblock(512)
|
55
|
+
rescue IO::WaitReadable
|
56
|
+
# handle wait
|
57
|
+
rescue ::EOFError
|
58
|
+
# handle eof
|
59
|
+
ensure
|
60
|
+
reader.close
|
61
|
+
end
|
39
62
|
```
|
40
63
|
|
41
64
|
You can create and read `tar.Z` archives with `minitar` for example.
|
@@ -63,59 +86,26 @@ end
|
|
63
86
|
|
64
87
|
## Options
|
65
88
|
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
89
|
+
| Option | Values | Default | Description |
|
90
|
+
|-----------------------------|------------|----------|-------------|
|
91
|
+
| `source_buffer_length` | 0, 2 - inf | 0 (auto) | internal buffer length for source data |
|
92
|
+
| `destination_buffer_length` | 0, 2 - inf | 0 (auto) | internal buffer length for description data |
|
93
|
+
| `max_code_bit_length` | 9 - 16 | 16 | max code bit length |
|
94
|
+
| `block_mode` | true/false | true | enables block mode |
|
95
|
+
| `without_magic_header` | true/false | false | disables magic header |
|
96
|
+
| `msb` | true/false | false | enables most significant bit mode |
|
97
|
+
| `unaligned_bit_groups` | true/false | false | enables unaligned bit groups |
|
98
|
+
| `quiet` | true/false | false | disables lzws library logging |
|
72
99
|
|
73
100
|
There are internal buffers for compressed and decompressed data.
|
74
|
-
For example you want to use 1 KB as
|
75
|
-
You want to use 256 B as
|
76
|
-
|
77
|
-
Values: 0, 2 - infinity, default value: 0.
|
78
|
-
0 means automatic buffer length selection.
|
79
|
-
1 byte is not enough, 2 bytes is minimal buffer length.
|
80
|
-
|
81
|
-
```
|
82
|
-
:max_code_bit_length
|
83
|
-
```
|
84
|
-
|
85
|
-
Values: `LZWS::Option::LOWEST_MAX_CODE_BIT_LENGTH` - `LZWS::Option::BIGGEST_MAX_CODE_BIT_LENGTH`, default value: `LZWS::Option::BIGGEST_MAX_CODE_BIT_LENGTH`.
|
86
|
-
|
87
|
-
```
|
88
|
-
:block_mode
|
89
|
-
```
|
90
|
-
|
91
|
-
Values: true/false, default value: true.
|
92
|
-
|
93
|
-
```
|
94
|
-
:without_magic_header
|
95
|
-
```
|
96
|
-
|
97
|
-
Values: true/false, default value: false.
|
98
|
-
|
99
|
-
```
|
100
|
-
:msb
|
101
|
-
```
|
102
|
-
|
103
|
-
Values: true/false, default value: false.
|
104
|
-
|
105
|
-
```
|
106
|
-
:unaligned_bit_groups
|
107
|
-
```
|
108
|
-
|
109
|
-
Values: true/false, default value: false.
|
110
|
-
|
111
|
-
```
|
112
|
-
:quiet
|
113
|
-
```
|
101
|
+
For example you want to use 1 KB as `source_buffer_length` for compressor - please use 256 B as `destination_buffer_length`.
|
102
|
+
You want to use 256 B as `source_buffer_length` for decompressor - please use 1 KB as `destination_buffer_length`.
|
114
103
|
|
115
|
-
|
116
|
-
Disables lzws library logging.
|
104
|
+
You can also read lzws docs for more info about options.
|
117
105
|
|
118
|
-
|
106
|
+
| Option | Related constants |
|
107
|
+
|-----------------------|-------------------|
|
108
|
+
| `max_code_bit_length` | `LZWS::Option::LOWEST_MAX_CODE_BIT_LENGTH` = 9, `LZWS::Option::BIGGEST_MAX_CODE_BIT_LENGTH` = 16 |
|
119
109
|
|
120
110
|
Possible compressor options:
|
121
111
|
```
|
@@ -186,7 +176,7 @@ File maintains both source and destination buffers, it accepts both `source_buff
|
|
186
176
|
|
187
177
|
## Stream::Writer
|
188
178
|
|
189
|
-
Its behaviour is similar to builtin [`Zlib::GzipWriter`](https://ruby-doc.org/stdlib-2.
|
179
|
+
Its behaviour is similar to builtin [`Zlib::GzipWriter`](https://ruby-doc.org/stdlib-2.7.0/libdoc/zlib/rdoc/Zlib/GzipWriter.html).
|
190
180
|
|
191
181
|
Writer maintains destination buffer only, so it accepts `destination_buffer_length` option only.
|
192
182
|
|
@@ -220,7 +210,7 @@ Set another encodings, `nil` is just for compatibility with `IO`.
|
|
220
210
|
#tell
|
221
211
|
```
|
222
212
|
|
223
|
-
See [`IO`](https://ruby-doc.org/core-2.
|
213
|
+
See [`IO`](https://ruby-doc.org/core-2.7.0/IO.html) docs.
|
224
214
|
|
225
215
|
```
|
226
216
|
#write(*objects)
|
@@ -230,7 +220,7 @@ See [`IO`](https://ruby-doc.org/core-2.6.1/IO.html) docs.
|
|
230
220
|
#closed?
|
231
221
|
```
|
232
222
|
|
233
|
-
See [`Zlib::GzipWriter`](https://ruby-doc.org/stdlib-2.
|
223
|
+
See [`Zlib::GzipWriter`](https://ruby-doc.org/stdlib-2.7.0/libdoc/zlib/rdoc/Zlib/GzipWriter.html) docs.
|
234
224
|
|
235
225
|
```
|
236
226
|
#write_nonblock(object, *options)
|
@@ -252,11 +242,11 @@ Behaviour is the same as `IO#write_nonblock` method.
|
|
252
242
|
#puts(*objects)
|
253
243
|
```
|
254
244
|
|
255
|
-
Typical helpers, see [`Zlib::GzipWriter`](https://ruby-doc.org/stdlib-2.
|
245
|
+
Typical helpers, see [`Zlib::GzipWriter`](https://ruby-doc.org/stdlib-2.7.0/libdoc/zlib/rdoc/Zlib/GzipWriter.html) docs.
|
256
246
|
|
257
247
|
## Stream::Reader
|
258
248
|
|
259
|
-
Its behaviour is similar to builtin [`Zlib::GzipReader`](https://ruby-doc.org/stdlib-2.
|
249
|
+
Its behaviour is similar to builtin [`Zlib::GzipReader`](https://ruby-doc.org/stdlib-2.7.0/libdoc/zlib/rdoc/Zlib/GzipReader.html).
|
260
250
|
|
261
251
|
Reader maintains both source and destination buffers, it accepts both `source_buffer_length` and `destination_buffer_length` options.
|
262
252
|
|
@@ -291,7 +281,7 @@ Set another encodings.
|
|
291
281
|
#tell
|
292
282
|
```
|
293
283
|
|
294
|
-
See [`IO`](https://ruby-doc.org/core-2.
|
284
|
+
See [`IO`](https://ruby-doc.org/core-2.7.0/IO.html) docs.
|
295
285
|
|
296
286
|
```
|
297
287
|
#read(bytes_to_read = nil, out_buffer = nil)
|
@@ -301,14 +291,14 @@ See [`IO`](https://ruby-doc.org/core-2.6.1/IO.html) docs.
|
|
301
291
|
#closed?
|
302
292
|
```
|
303
293
|
|
304
|
-
See [`Zlib::GzipReader`](https://ruby-doc.org/stdlib-2.
|
294
|
+
See [`Zlib::GzipReader`](https://ruby-doc.org/stdlib-2.7.0/libdoc/zlib/rdoc/Zlib/GzipReader.html) docs.
|
305
295
|
|
306
296
|
```
|
307
297
|
#readpartial(bytes_to_read = nil, out_buffer = nil)
|
308
298
|
#read_nonblock(bytes_to_read, out_buffer = nil, *options)
|
309
299
|
```
|
310
300
|
|
311
|
-
See [`IO`](https://ruby-doc.org/core-2.
|
301
|
+
See [`IO`](https://ruby-doc.org/core-2.7.0/IO.html) docs.
|
312
302
|
|
313
303
|
```
|
314
304
|
#getbyte
|
@@ -331,13 +321,13 @@ See [`IO`](https://ruby-doc.org/core-2.6.1/IO.html) docs.
|
|
331
321
|
#ungetline(line)
|
332
322
|
```
|
333
323
|
|
334
|
-
Typical helpers, see [`Zlib::GzipReader`](https://ruby-doc.org/stdlib-2.
|
324
|
+
Typical helpers, see [`Zlib::GzipReader`](https://ruby-doc.org/stdlib-2.7.0/libdoc/zlib/rdoc/Zlib/GzipReader.html) docs.
|
335
325
|
|
336
326
|
## CI
|
337
327
|
|
338
|
-
|
339
|
-
|
340
|
-
|
328
|
+
See universal test script [scripts/ci_test.sh](scripts/ci_test.sh) for CI.
|
329
|
+
Please visit [scripts/test-images](scripts/test-images).
|
330
|
+
You can run this test script using many native and cross images.
|
341
331
|
|
342
332
|
## License
|
343
333
|
|
data/ext/extconf.rb
CHANGED
@@ -13,10 +13,10 @@ end
|
|
13
13
|
|
14
14
|
require_header "lzws/buffer.h"
|
15
15
|
require_header "lzws/common.h", %w[lzws_result_t]
|
16
|
-
require_header "lzws/compressor/common.h"
|
16
|
+
require_header "lzws/compressor/common.h", %w[lzws_compressor_options_t]
|
17
17
|
require_header "lzws/compressor/main.h"
|
18
18
|
require_header "lzws/compressor/state.h", %w[lzws_compressor_state_t]
|
19
|
-
require_header "lzws/decompressor/common.h"
|
19
|
+
require_header "lzws/decompressor/common.h", %w[lzws_decompressor_options_t]
|
20
20
|
require_header "lzws/decompressor/main.h"
|
21
21
|
require_header "lzws/decompressor/state.h", %w[lzws_decompressor_state_t]
|
22
22
|
require_header "lzws/file.h"
|
@@ -66,6 +66,13 @@ $srcs = %w[
|
|
66
66
|
.map { |name| "src/#{extension_name}/#{name}.c" }
|
67
67
|
.freeze
|
68
68
|
|
69
|
+
# Removing library duplicates.
|
70
|
+
$libs = $libs.split(%r{\s})
|
71
|
+
.reject(&:empty?)
|
72
|
+
.sort
|
73
|
+
.uniq
|
74
|
+
.join " "
|
75
|
+
|
69
76
|
if ENV["CI"] || ENV["COVERAGE"]
|
70
77
|
$CFLAGS << " --coverage"
|
71
78
|
$LDFLAGS << " --coverage"
|
data/ext/lzws_ext/buffer.c
CHANGED
@@ -16,6 +16,7 @@ VALUE lzws_ext_resize_string_buffer(VALUE args)
|
|
16
16
|
{
|
17
17
|
VALUE buffer = rb_ary_entry(args, 0);
|
18
18
|
VALUE length = rb_ary_entry(args, 1);
|
19
|
+
|
19
20
|
return rb_str_resize(buffer, NUM2SIZET(length));
|
20
21
|
}
|
21
22
|
|
@@ -23,8 +24,21 @@ void lzws_ext_buffer_exports(VALUE root_module)
|
|
23
24
|
{
|
24
25
|
VALUE module = rb_define_module_under(root_module, "Buffer");
|
25
26
|
|
26
|
-
rb_define_const(
|
27
|
-
|
28
|
-
|
29
|
-
rb_define_const(
|
27
|
+
rb_define_const(
|
28
|
+
module, "DEFAULT_SOURCE_BUFFER_LENGTH_FOR_COMPRESSOR", SIZET2NUM(LZWS_DEFAULT_SOURCE_BUFFER_LENGTH_FOR_COMPRESSOR));
|
29
|
+
|
30
|
+
rb_define_const(
|
31
|
+
module,
|
32
|
+
"DEFAULT_DESTINATION_BUFFER_LENGTH_FOR_COMPRESSOR",
|
33
|
+
SIZET2NUM(LZWS_DEFAULT_DESTINATION_BUFFER_LENGTH_FOR_COMPRESSOR));
|
34
|
+
|
35
|
+
rb_define_const(
|
36
|
+
module,
|
37
|
+
"DEFAULT_SOURCE_BUFFER_LENGTH_FOR_DECOMPRESSOR",
|
38
|
+
SIZET2NUM(LZWS_DEFAULT_SOURCE_BUFFER_LENGTH_FOR_DECOMPRESSOR));
|
39
|
+
|
40
|
+
rb_define_const(
|
41
|
+
module,
|
42
|
+
"DEFAULT_DESTINATION_BUFFER_LENGTH_FOR_DECOMPRESSOR",
|
43
|
+
SIZET2NUM(LZWS_DEFAULT_DESTINATION_BUFFER_LENGTH_FOR_DECOMPRESSOR));
|
30
44
|
}
|
data/ext/lzws_ext/common.h
CHANGED
data/ext/lzws_ext/error.c
CHANGED
data/ext/lzws_ext/error.h
CHANGED
data/ext/lzws_ext/io.c
CHANGED
@@ -1,17 +1,15 @@
|
|
1
1
|
// Ruby bindings for lzws library.
|
2
2
|
// Copyright (c) 2019 AUTHORS, MIT License.
|
3
3
|
|
4
|
-
#include "
|
4
|
+
#include "lzws_ext/io.h"
|
5
5
|
|
6
|
-
#include <lzws/common.h>
|
7
6
|
#include <lzws/file.h>
|
8
7
|
|
9
|
-
#include "lzws_ext/common.h"
|
10
8
|
#include "lzws_ext/error.h"
|
11
|
-
#include "lzws_ext/io.h"
|
12
9
|
#include "lzws_ext/macro.h"
|
13
10
|
#include "lzws_ext/option.h"
|
14
11
|
#include "ruby.h"
|
12
|
+
#include "ruby/io.h"
|
15
13
|
|
16
14
|
#define GET_FILE(target) \
|
17
15
|
Check_Type(target, T_FILE); \
|
@@ -59,9 +57,7 @@ VALUE lzws_ext_compress_io(VALUE LZWS_EXT_UNUSED(self), VALUE source, VALUE dest
|
|
59
57
|
LZWS_EXT_GET_BUFFER_LENGTH_OPTION(options, destination_buffer_length);
|
60
58
|
|
61
59
|
lzws_result_t result = lzws_compress_file(
|
62
|
-
source_file, source_buffer_length,
|
63
|
-
destination_file, destination_buffer_length,
|
64
|
-
without_magic_header, max_code_bit_length, block_mode, msb, unaligned_bit_groups, quiet);
|
60
|
+
source_file, source_buffer_length, destination_file, destination_buffer_length, &compressor_options);
|
65
61
|
|
66
62
|
if (result != 0) {
|
67
63
|
lzws_ext_raise_error(get_file_error(result));
|
@@ -83,9 +79,7 @@ VALUE lzws_ext_decompress_io(VALUE LZWS_EXT_UNUSED(self), VALUE source, VALUE de
|
|
83
79
|
LZWS_EXT_GET_BUFFER_LENGTH_OPTION(options, destination_buffer_length);
|
84
80
|
|
85
81
|
lzws_result_t result = lzws_decompress_file(
|
86
|
-
source_file, source_buffer_length,
|
87
|
-
destination_file, destination_buffer_length,
|
88
|
-
without_magic_header, msb, unaligned_bit_groups, quiet);
|
82
|
+
source_file, source_buffer_length, destination_file, destination_buffer_length, &decompressor_options);
|
89
83
|
|
90
84
|
if (result != 0) {
|
91
85
|
lzws_ext_raise_error(get_file_error(result));
|
data/ext/lzws_ext/main.c
CHANGED
@@ -2,8 +2,8 @@
|
|
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"
|
6
|
+
#include "lzws_ext/option.h"
|
7
7
|
#include "lzws_ext/stream/compressor.h"
|
8
8
|
#include "lzws_ext/stream/decompressor.h"
|
9
9
|
#include "lzws_ext/string.h"
|
@@ -15,6 +15,7 @@ void Init_lzws_ext()
|
|
15
15
|
|
16
16
|
lzws_ext_buffer_exports(root_module);
|
17
17
|
lzws_ext_io_exports(root_module);
|
18
|
+
lzws_ext_option_exports(root_module);
|
18
19
|
lzws_ext_compressor_exports(root_module);
|
19
20
|
lzws_ext_decompressor_exports(root_module);
|
20
21
|
lzws_ext_string_exports(root_module);
|
data/ext/lzws_ext/option.c
CHANGED
@@ -3,36 +3,41 @@
|
|
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
|
|
9
|
+
// -- values --
|
10
|
+
|
12
11
|
static inline VALUE get_raw_option_value(VALUE options, const char* name)
|
13
12
|
{
|
14
13
|
return rb_funcall(options, rb_intern("[]"), 1, ID2SYM(rb_intern(name)));
|
15
14
|
}
|
16
15
|
|
17
|
-
|
16
|
+
void lzws_ext_get_bool_option(VALUE options, bool* option, const char* name)
|
18
17
|
{
|
19
18
|
VALUE raw_value = get_raw_option_value(options, name);
|
19
|
+
if (raw_value == Qnil) {
|
20
|
+
return;
|
21
|
+
}
|
20
22
|
|
21
23
|
int raw_type = TYPE(raw_value);
|
22
24
|
if (raw_type != T_TRUE && raw_type != T_FALSE) {
|
23
25
|
lzws_ext_raise_error(LZWS_EXT_ERROR_VALIDATE_FAILED);
|
24
26
|
}
|
25
27
|
|
26
|
-
|
28
|
+
*option = raw_type == T_TRUE;
|
27
29
|
}
|
28
30
|
|
29
|
-
|
31
|
+
void lzws_ext_get_max_code_bit_length_option(VALUE options, lzws_byte_fast_t* option, const char* name)
|
30
32
|
{
|
31
33
|
VALUE raw_value = get_raw_option_value(options, name);
|
34
|
+
if (raw_value == Qnil) {
|
35
|
+
return;
|
36
|
+
}
|
32
37
|
|
33
38
|
Check_Type(raw_value, T_FIXNUM);
|
34
39
|
|
35
|
-
|
40
|
+
*option = NUM2UINT(raw_value);
|
36
41
|
}
|
37
42
|
|
38
43
|
size_t lzws_ext_get_size_option_value(VALUE options, const char* name)
|
@@ -43,3 +48,13 @@ size_t lzws_ext_get_size_option_value(VALUE options, const char* name)
|
|
43
48
|
|
44
49
|
return NUM2SIZET(raw_value);
|
45
50
|
}
|
51
|
+
|
52
|
+
// -- exports --
|
53
|
+
|
54
|
+
void lzws_ext_option_exports(VALUE root_module)
|
55
|
+
{
|
56
|
+
VALUE module = rb_define_module_under(root_module, "Option");
|
57
|
+
|
58
|
+
rb_define_const(module, "LOWEST_MAX_CODE_BIT_LENGTH", UINT2NUM(LZWS_LOWEST_MAX_CODE_BIT_LENGTH));
|
59
|
+
rb_define_const(module, "BIGGEST_MAX_CODE_BIT_LENGTH", UINT2NUM(LZWS_BIGGEST_MAX_CODE_BIT_LENGTH));
|
60
|
+
}
|
data/ext/lzws_ext/option.h
CHANGED
@@ -4,39 +4,44 @@
|
|
4
4
|
#if !defined(LZWS_EXT_OPTIONS_H)
|
5
5
|
#define LZWS_EXT_OPTIONS_H
|
6
6
|
|
7
|
+
#include <lzws/compressor/common.h>
|
8
|
+
#include <lzws/decompressor/common.h>
|
7
9
|
#include <stdbool.h>
|
8
10
|
#include <stdlib.h>
|
9
11
|
|
10
12
|
#include "ruby.h"
|
11
13
|
|
12
|
-
|
13
|
-
|
14
|
-
size_t lzws_ext_get_size_option_value(VALUE options, const char* name);
|
14
|
+
void lzws_ext_get_bool_option(VALUE options, bool* option, const char* name);
|
15
|
+
void lzws_ext_get_max_code_bit_length_option(VALUE options, lzws_byte_fast_t* option, const char* name);
|
15
16
|
|
16
|
-
#define LZWS_EXT_GET_BOOL_OPTION(options, name) \
|
17
|
-
|
17
|
+
#define LZWS_EXT_GET_BOOL_OPTION(options, target_options, name) \
|
18
|
+
lzws_ext_get_bool_option(options, &target_options.name, #name);
|
18
19
|
|
19
|
-
#define
|
20
|
-
|
20
|
+
#define LZWS_EXT_GET_MAX_CODE_BIT_LENGTH_OPTION(options, target_options, name) \
|
21
|
+
lzws_ext_get_max_code_bit_length_option(options, &target_options.name, #name);
|
21
22
|
|
22
|
-
#define
|
23
|
-
|
23
|
+
#define LZWS_EXT_GET_COMPRESSOR_OPTIONS(options) \
|
24
|
+
lzws_compressor_options_t compressor_options = LZWS_COMPRESSOR_DEFAULT_OPTIONS; \
|
25
|
+
\
|
26
|
+
LZWS_EXT_GET_BOOL_OPTION(options, compressor_options, without_magic_header); \
|
27
|
+
LZWS_EXT_GET_MAX_CODE_BIT_LENGTH_OPTION(options, compressor_options, max_code_bit_length); \
|
28
|
+
LZWS_EXT_GET_BOOL_OPTION(options, compressor_options, block_mode); \
|
29
|
+
LZWS_EXT_GET_BOOL_OPTION(options, compressor_options, msb); \
|
30
|
+
LZWS_EXT_GET_BOOL_OPTION(options, compressor_options, unaligned_bit_groups); \
|
31
|
+
LZWS_EXT_GET_BOOL_OPTION(options, compressor_options, quiet);
|
24
32
|
|
25
|
-
#define
|
26
|
-
|
27
|
-
|
28
|
-
LZWS_EXT_GET_BOOL_OPTION(options,
|
29
|
-
LZWS_EXT_GET_BOOL_OPTION(options, msb);
|
30
|
-
LZWS_EXT_GET_BOOL_OPTION(options, unaligned_bit_groups);
|
31
|
-
LZWS_EXT_GET_BOOL_OPTION(options, quiet);
|
33
|
+
#define LZWS_EXT_GET_DECOMPRESSOR_OPTIONS(options) \
|
34
|
+
lzws_decompressor_options_t decompressor_options = LZWS_DECOMPRESSOR_DEFAULT_OPTIONS; \
|
35
|
+
\
|
36
|
+
LZWS_EXT_GET_BOOL_OPTION(options, decompressor_options, without_magic_header); \
|
37
|
+
LZWS_EXT_GET_BOOL_OPTION(options, decompressor_options, msb); \
|
38
|
+
LZWS_EXT_GET_BOOL_OPTION(options, decompressor_options, unaligned_bit_groups); \
|
39
|
+
LZWS_EXT_GET_BOOL_OPTION(options, decompressor_options, quiet);
|
32
40
|
|
33
|
-
|
34
|
-
LZWS_EXT_GET_BOOL_OPTION(options, without_magic_header); \
|
35
|
-
LZWS_EXT_GET_BOOL_OPTION(options, msb); \
|
36
|
-
LZWS_EXT_GET_BOOL_OPTION(options, unaligned_bit_groups); \
|
37
|
-
LZWS_EXT_GET_BOOL_OPTION(options, quiet);
|
41
|
+
size_t lzws_ext_get_size_option_value(VALUE options, const char* name);
|
38
42
|
|
39
|
-
#define LZWS_EXT_GET_BUFFER_LENGTH_OPTION(options, name)
|
40
|
-
|
43
|
+
#define LZWS_EXT_GET_BUFFER_LENGTH_OPTION(options, name) size_t name = lzws_ext_get_size_option_value(options, #name);
|
44
|
+
|
45
|
+
void lzws_ext_option_exports(VALUE root_module);
|
41
46
|
|
42
47
|
#endif // LZWS_EXT_OPTIONS_H
|