ruby-lzws 1.0.0 → 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: 5e42a999e18187b07931b4c7127274339f8d6eb61490d2c3bcd504180c674d43
4
- data.tar.gz: 8516d4a94686aeeb2587fcb6bd862dc85ff651ac6e71ae0449e3797a85653f78
3
+ metadata.gz: 6fc8861bd91fe484c375cdeae3ad55e478727e8a1314117fb3897cef408bd401
4
+ data.tar.gz: 9b7a0d9cd62930a12250641599638d80abb34737bae20842109d91f1dfee84a8
5
5
  SHA512:
6
- metadata.gz: 4c8f80f27ac4b2e12bc3628468b94bbebe5b00b688a6dc586013797b5eabb8a1a85da39fdd2ba5d48ed81d71d77df463800f6ef8c285d41bf057c1d306ed2727
7
- data.tar.gz: f4ced4337b346873836d004c57ca6411f62ba604d32a69001658db3705c4098f1a938e23c2242092bd76e645792824daeba93680ea3d3da5c4529872279095cc
6
+ metadata.gz: 880eb17f48cca872b77a56936aedebe4aa416eb971e51743550e0bd02c473568fb638d412deab64c522fa84895732c9f91da338a7d4f79bd3ac4c382f35326eb
7
+ data.tar.gz: e29e72c646f05e55ec4411a06e4be7122581962d9fe46164bc6bbaeefd1e874595ad74783503f76bf049096730043032976c8595e2d7903d9acb3ab9bb39b8cc
data/README.md CHANGED
@@ -1,13 +1,14 @@
1
1
  # Ruby bindings for lzws library
2
2
 
3
- [![Travis build status](https://travis-ci.org/andrew-aladev/ruby-lzws.svg?branch=master)](https://travis-ci.org/andrew-aladev/ruby-lzws)
4
- [![AppVeyor build 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 | Cirrus | 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) | [![Cirrus test status](https://api.cirrus-ci.com/github/andrew-aladev/ruby-lzws.svg?branch=master)](https://cirrus-ci.com/github/andrew-aladev/ruby-lzws) | [![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) |
5
6
 
6
7
  See [lzws library](https://github.com/andrew-aladev/lzws).
7
8
 
8
9
  ## Installation
9
10
 
10
- Please install lzws library first.
11
+ Please install lzws library first, use latest 1.3.0+ version.
11
12
 
12
13
  ```sh
13
14
  gem install ruby-lzws
@@ -38,7 +39,7 @@ puts LZWS::Stream::Reader.open("file.txt.Z") { |reader| reader.read }
38
39
  ```
39
40
 
40
41
  You can create and read `tar.Z` archives with `minitar` for example.
41
- LZWS is fully compatible with UNIX compress (with default options).
42
+ LZWS is compatible with UNIX compress (with default options).
42
43
 
43
44
  ```ruby
44
45
  require "lzws"
@@ -60,30 +61,86 @@ LZWS::Stream::Reader.open "file.tar.Z" do |reader|
60
61
  end
61
62
  ```
62
63
 
63
- Each API supports additional options, please read lzws docs for more info.
64
+ ## Options
64
65
 
65
- Compressor:
66
+ Each API supports several options:
67
+
68
+ ```
69
+ :source_buffer_length
70
+ :destination_buffer_length
71
+ ```
72
+
73
+ There are internal buffers for compressed and decompressed data.
74
+ For example you want to use 1 KB as source buffer length for compressor - please use 256 B as destination buffer length.
75
+ You want to use 256 B as source buffer length for decompressor - please use 1 KB as destination buffer length.
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.
66
80
 
67
81
  ```
68
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
+ ```
69
88
  :block_mode
70
- :buffer_length
89
+ ```
90
+
91
+ Values: true/false, default value: true.
92
+
93
+ ```
71
94
  :without_magic_header
95
+ ```
96
+
97
+ Values: true/false, default value: false.
98
+
99
+ ```
72
100
  :msb
101
+ ```
102
+
103
+ Values: true/false, default value: false.
104
+
105
+ ```
73
106
  :unaligned_bit_groups
107
+ ```
108
+
109
+ Values: true/false, default value: false.
110
+
111
+ ```
74
112
  :quiet
75
113
  ```
76
114
 
77
- Decompressor:
115
+ Values: true/false, default value: false.
116
+ Disables lzws library logging.
117
+
118
+ Please read lzws docs for more info about options.
119
+
120
+ Possible compressor options:
121
+ ```
122
+ :source_buffer_length
123
+ :destination_buffer_length
124
+ :max_code_bit_length
125
+ :block_mode
126
+ :without_magic_header
127
+ :msb
128
+ :unaligned_bit_groups
129
+ :quiet
130
+ ```
78
131
 
132
+ Possible decompressor options:
79
133
  ```
80
- :buffer_length
134
+ :source_buffer_length
135
+ :destination_buffer_length
81
136
  :without_magic_header
82
137
  :msb
83
138
  :unaligned_bit_groups
84
139
  :quiet
85
140
  ```
86
141
 
142
+ Example:
143
+
87
144
  ```ruby
88
145
  require "lzws"
89
146
 
@@ -91,7 +148,7 @@ data = LZWS::String.compress "TOBEORNOTTOBEORTOBEORNOT", :msb => true
91
148
  puts LZWS::String.decompress(data, :msb => true)
92
149
  ```
93
150
 
94
- You can use `Content-Encoding: compress`.
151
+ Default options are compatible with UNIX compress (`Content-Encoding: compress`):
95
152
 
96
153
  ```ruby
97
154
  require "lzws"
@@ -103,50 +160,91 @@ get "/" do
103
160
  end
104
161
  ```
105
162
 
106
- ## Docs
163
+ Please read more about compatibility in lzws docs.
107
164
 
108
- `LZWS::String`:
165
+ ## String
166
+
167
+ String maintains destination buffer only, so it accepts `destination_buffer_length` option only.
109
168
 
110
169
  ```
111
170
  ::compress(source, options = {})
112
171
  ::decompress(source, options = {})
113
172
  ```
114
173
 
115
- `LZWS::File`:
174
+ `source` is a source string.
175
+
176
+ ## File
177
+
178
+ File maintains both source and destination buffers, it accepts both `source_buffer_length` and `destination_buffer_length` options.
116
179
 
117
180
  ```
118
181
  ::compress(source, destination, options = {})
119
182
  ::decompress(source, destination, options = {})
120
183
  ```
121
184
 
122
- `LZWS::Stream::Writer` and `LZWS::Stream::Reader`:
185
+ `source` and `destination` are file pathes.
186
+
187
+ ## Stream::Writer
188
+
189
+ Its behaviour is similar to builtin [`Zlib::GzipWriter`](https://ruby-doc.org/stdlib-2.7.0/libdoc/zlib/rdoc/Zlib/GzipWriter.html).
190
+
191
+ Writer maintains destination buffer only, so it accepts `destination_buffer_length` option only.
192
+
193
+ ```
194
+ ::open(file_path, options = {}, :external_encoding => nil, :transcode_options => {}, &block)
195
+ ```
196
+
197
+ Open file path and create stream writer associated with opened file.
198
+ Data will be transcoded to `:external_encoding` using `:transcode_options` before compressing.
199
+
200
+ ```
201
+ ::new(destination_io, options = {}, :external_encoding => nil, :transcode_options => {})
202
+ ```
203
+
204
+ Create stream writer associated with destination io.
205
+ Data will be transcoded to `:external_encoding` using `:transcode_options` before compressing.
206
+
207
+ ```
208
+ #set_encoding(external_encoding, nil, transcode_options)
209
+ ```
210
+
211
+ Set another encodings, `nil` is just for compatibility with `IO`.
123
212
 
124
213
  ```
125
- ::open(file_path, options = {}, :external_encoding => nil, :internal_encoding => nil, &block)
126
214
  #io
215
+ #to_io
127
216
  #stat
128
217
  #external_encoding
129
- #internal_encoding
218
+ #transcode_options
130
219
  #pos
131
220
  #tell
132
- #advise
133
- #set_encoding(external_encoding, internal_encoding, transcode_options)
221
+ ```
222
+
223
+ See [`IO`](https://ruby-doc.org/core-2.7.0/IO.html) docs.
224
+
225
+ ```
226
+ #write(*objects)
227
+ #flush
134
228
  #rewind
135
229
  #close
136
230
  #closed?
137
- #to_io
138
231
  ```
139
232
 
140
- `Stream::Writer`:
233
+ See [`Zlib::GzipWriter`](https://ruby-doc.org/stdlib-2.7.0/libdoc/zlib/rdoc/Zlib/GzipWriter.html) docs.
141
234
 
142
235
  ```
143
- ::new(destination_io, options = {}, :external_encoding => nil)
144
- #write(*objects)
145
- #flush
146
236
  #write_nonblock(object, *options)
147
237
  #flush_nonblock(*options)
148
238
  #rewind_nonblock(*options)
149
239
  #close_nonblock(*options)
240
+ ```
241
+
242
+ Special asynchronous methods missing in `Zlib::GzipWriter`.
243
+ `rewind` wants to `close`, `close` wants to `write` something and `flush`, `flush` want to `write` something.
244
+ So it is possible to have asynchronous variants for these synchronous methods.
245
+ Behaviour is the same as `IO#write_nonblock` method.
246
+
247
+ ```
150
248
  #<<(object)
151
249
  #print(*objects)
152
250
  #printf(*args)
@@ -154,24 +252,77 @@ end
154
252
  #puts(*objects)
155
253
  ```
156
254
 
157
- `Stream::Reader`:
255
+ Typical helpers, see [`Zlib::GzipWriter`](https://ruby-doc.org/stdlib-2.7.0/libdoc/zlib/rdoc/Zlib/GzipWriter.html) docs.
256
+
257
+ ## Stream::Reader
258
+
259
+ Its behaviour is similar to builtin [`Zlib::GzipReader`](https://ruby-doc.org/stdlib-2.7.0/libdoc/zlib/rdoc/Zlib/GzipReader.html).
260
+
261
+ Reader maintains both source and destination buffers, it accepts both `source_buffer_length` and `destination_buffer_length` options.
262
+
263
+ ```
264
+ ::open(file_path, options = {}, :external_encoding => nil, :internal_encoding => nil, :transcode_options => {}, &block)
265
+ ```
266
+
267
+ Open file path and create stream reader associated with opened file.
268
+ Data will be force encoded to `:external_encoding` and transcoded to `:internal_encoding` using `:transcode_options` after decompressing.
269
+
270
+ ```
271
+ ::new(source_io, options = {}, :external_encoding => nil, :internal_encoding => nil, :transcode_options => {})
272
+ ```
273
+
274
+ Create stream reader associated with source io.
275
+ Data will be force encoded to `:external_encoding` and transcoded to `:internal_encoding` using `:transcode_options` after decompressing.
276
+
277
+ ```
278
+ #set_encoding(external_encoding, internal_encoding, transcode_options)
279
+ ```
280
+
281
+ Set another encodings.
282
+
283
+ ```
284
+ #io
285
+ #to_io
286
+ #stat
287
+ #external_encoding
288
+ #internal_encoding
289
+ #transcode_options
290
+ #pos
291
+ #tell
292
+ ```
293
+
294
+ See [`IO`](https://ruby-doc.org/core-2.7.0/IO.html) docs.
158
295
 
159
296
  ```
160
- ::new(source_io, options = {}, :external_encoding => nil, :internal_encoding => nil)
161
- #lineno
162
- #lineno=
163
297
  #read(bytes_to_read = nil, out_buffer = nil)
298
+ #eof?
299
+ #rewind
300
+ #close
301
+ #closed?
302
+ ```
303
+
304
+ See [`Zlib::GzipReader`](https://ruby-doc.org/stdlib-2.7.0/libdoc/zlib/rdoc/Zlib/GzipReader.html) docs.
305
+
306
+ ```
164
307
  #readpartial(bytes_to_read = nil, out_buffer = nil)
165
308
  #read_nonblock(bytes_to_read, out_buffer = nil, *options)
166
- #eof?
309
+ ```
310
+
311
+ See [`IO`](https://ruby-doc.org/core-2.7.0/IO.html) docs.
312
+
313
+ ```
167
314
  #getbyte
168
315
  #each_byte(&block)
169
316
  #readbyte
170
317
  #ungetbyte(byte)
318
+
171
319
  #getc
172
320
  #readchar
173
321
  #each_char(&block)
174
322
  #ungetc(char)
323
+
324
+ #lineno
325
+ #lineno=
175
326
  #gets(separator = $OUTPUT_RECORD_SEPARATOR, limit = nil)
176
327
  #readline
177
328
  #readlines
@@ -180,8 +331,15 @@ end
180
331
  #ungetline(line)
181
332
  ```
182
333
 
183
- `LZWS::Stream::Writer` and `LZWS::Stream::Reader` behaviour is the same as builtin [`Zlib::GzipWriter`](https://ruby-doc.org/stdlib-2.6.3/libdoc/zlib/rdoc/Zlib/GzipReader.html), [`Zlib::GzipReader`](https://ruby-doc.org/stdlib-2.6.3/libdoc/zlib/rdoc/Zlib/GzipWriter.html) and [`IO`](https://ruby-doc.org/core-2.6.3/IO.html).
184
- Please read these method descriptions in ruby doc.
334
+ Typical helpers, see [`Zlib::GzipReader`](https://ruby-doc.org/stdlib-2.7.0/libdoc/zlib/rdoc/Zlib/GzipReader.html) docs.
335
+
336
+ ## CI
337
+
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.
185
343
 
186
344
  ## License
187
345
 
@@ -3,74 +3,76 @@
3
3
 
4
4
  require "mkmf"
5
5
 
6
- def require_header(name)
6
+ def require_header(name, types = [])
7
7
  abort "Can't find #{name} header" unless find_header name
8
+
9
+ types.each do |type|
10
+ abort "Can't find #{type} type in #{name} header" unless find_type type, nil, name
11
+ end
8
12
  end
9
13
 
10
14
  require_header "lzws/buffer.h"
15
+ require_header "lzws/common.h", %w[lzws_result_t]
11
16
  require_header "lzws/compressor/common.h"
12
- require_header "lzws/compressor/header.h"
13
17
  require_header "lzws/compressor/main.h"
14
- require_header "lzws/compressor/state.h"
18
+ require_header "lzws/compressor/state.h", %w[lzws_compressor_state_t]
15
19
  require_header "lzws/decompressor/common.h"
16
- require_header "lzws/decompressor/header.h"
17
20
  require_header "lzws/decompressor/main.h"
18
- require_header "lzws/decompressor/state.h"
21
+ require_header "lzws/decompressor/state.h", %w[lzws_decompressor_state_t]
19
22
  require_header "lzws/file.h"
20
- require_header "lzws/string.h"
21
23
 
22
24
  def require_library(name, functions)
23
25
  functions.each do |function|
24
- abort "Can't find #{name} library and #{function} function" unless find_library name, function
26
+ abort "Can't find #{function} function in #{name} library" unless find_library name, function
25
27
  end
26
28
  end
27
29
 
28
- functions = %w[
29
- lzws_create_buffer_for_compressor
30
- lzws_create_buffer_for_decompressor
31
- lzws_resize_buffer
32
-
33
- lzws_compress_string
34
- lzws_decompress_string
30
+ require_library(
31
+ "lzws",
32
+ %w[
33
+ lzws_create_source_buffer_for_compressor
34
+ lzws_create_destination_buffer_for_compressor
35
+ lzws_create_source_buffer_for_decompressor
36
+ lzws_create_destination_buffer_for_decompressor
35
37
 
36
- lzws_compress_file
37
- lzws_decompress_file
38
+ lzws_compressor_get_initial_state
39
+ lzws_compressor_free_state
40
+ lzws_compress
41
+ lzws_compressor_finish
38
42
 
39
- lzws_compressor_write_magic_header
40
- lzws_compressor_get_initial_state
41
- lzws_compress
42
- lzws_flush_compressor
43
- lzws_compressor_free_state
44
-
45
- lzws_decompressor_read_magic_header
46
- lzws_decompressor_get_initial_state
47
- lzws_decompress
48
- lzws_decompressor_free_state
49
- ]
50
- .freeze
43
+ lzws_decompressor_get_initial_state
44
+ lzws_decompressor_free_state
45
+ lzws_decompress
51
46
 
52
- require_library "lzws", functions
47
+ lzws_compress_file
48
+ lzws_decompress_file
49
+ ]
50
+ )
53
51
 
54
52
  extension_name = "lzws_ext".freeze
55
53
  dir_config extension_name
56
54
 
57
- sources = %w[
55
+ # rubocop:disable Style/GlobalVars
56
+ $srcs = %w[
58
57
  stream/compressor
59
58
  stream/decompressor
59
+ buffer
60
60
  error
61
61
  io
62
62
  main
63
63
  option
64
64
  string
65
65
  ]
66
+ .map { |name| "src/#{extension_name}/#{name}.c" }
66
67
  .freeze
67
68
 
68
- # rubocop:disable Style/GlobalVars
69
- $srcs = sources
70
- .map { |name| "src/#{extension_name}/#{name}.c" }
71
- .freeze
69
+ if ENV["CI"] || ENV["COVERAGE"]
70
+ $CFLAGS << " --coverage"
71
+ $LDFLAGS << " --coverage"
72
+ end
72
73
 
73
74
  $CFLAGS << " -Wno-declaration-after-statement"
75
+
74
76
  $VPATH << "$(srcdir)/#{extension_name}:$(srcdir)/#{extension_name}/stream"
75
77
  # rubocop:enable Style/GlobalVars
76
78