ruby-lzws 1.4.0 → 1.4.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,150 +1,16 @@
1
1
  # Ruby bindings for lzws library.
2
2
  # Copyright (c) 2019 AUTHORS, MIT License.
3
3
 
4
- require_relative "abstract"
4
+ require "adsp/stream/writer"
5
+
5
6
  require_relative "raw/compressor"
6
- require_relative "writer_helpers"
7
7
 
8
8
  module LZWS
9
9
  module Stream
10
- class Writer < Abstract
11
- include WriterHelpers
12
-
13
- def initialize(destination_io, options = {}, *args)
14
- @options = options
15
-
16
- super destination_io, *args
17
- end
18
-
19
- protected def create_raw_stream
20
- Raw::Compressor.new @options
21
- end
22
-
23
- # -- synchronous --
24
-
25
- def write(*objects)
26
- write_remaining_buffer
27
-
28
- bytes_written = 0
29
-
30
- objects.each do |object|
31
- source = transcode object.to_s
32
- bytes_written += raw_wrapper :write, source
33
- end
34
-
35
- @pos += bytes_written
36
-
37
- bytes_written
38
- end
39
-
40
- def flush
41
- finish :flush
42
-
43
- @io.flush
44
-
45
- self
46
- end
47
-
48
- def rewind
49
- finish :close
50
-
51
- super
52
- end
53
-
54
- def close
55
- finish :close
56
-
57
- super
58
- end
59
-
60
- protected def finish(method_name)
61
- write_remaining_buffer
62
-
63
- raw_wrapper method_name
64
- end
65
-
66
- protected def write_remaining_buffer
67
- return nil if @buffer.bytesize.zero?
68
-
69
- @io.write @buffer
70
-
71
- reset_buffer
72
- end
73
-
74
- protected def raw_wrapper(method_name, *args)
75
- @raw_stream.send(method_name, *args) { |portion| @io.write portion }
76
- end
77
-
78
- # -- asynchronous --
79
-
80
- # IO write nonblock can raise wait writable error.
81
- # After resolving this error user may provide same content again.
82
- # It is not possible to revert accepted content after error.
83
- # So we have to accept content after processing IO write nonblock.
84
- # It means that first write nonblock won't call IO write nonblock.
85
- def write_nonblock(object, *options)
86
- return 0 unless write_remaining_buffer_nonblock(*options)
87
-
88
- source = transcode object.to_s
89
- bytes_written = raw_nonblock_wrapper :write, source
90
- @pos += bytes_written
91
-
92
- bytes_written
93
- end
94
-
95
- def flush_nonblock(*options)
96
- return false unless finish_nonblock :flush, *options
97
-
98
- @io.flush
99
-
100
- true
101
- end
102
-
103
- def rewind_nonblock(*options)
104
- return false unless finish_nonblock :close, *options
105
-
106
- method(:rewind).super_method.call
107
-
108
- true
109
- end
110
-
111
- def close_nonblock(*options)
112
- return false unless finish_nonblock :close, *options
113
-
114
- method(:close).super_method.call
115
-
116
- true
117
- end
118
-
119
- protected def finish_nonblock(method_name, *options)
120
- return false unless write_remaining_buffer_nonblock(*options)
121
-
122
- raw_nonblock_wrapper method_name
123
-
124
- write_remaining_buffer_nonblock(*options)
125
- end
126
-
127
- protected def write_remaining_buffer_nonblock(*options)
128
- return true if @buffer.bytesize.zero?
129
-
130
- bytes_written = @io.write_nonblock @buffer, *options
131
- return false if bytes_written.zero?
132
-
133
- @buffer = @buffer.byteslice bytes_written, @buffer.bytesize - bytes_written
134
-
135
- @buffer.bytesize.zero?
136
- end
137
-
138
- protected def raw_nonblock_wrapper(method_name, *args)
139
- @raw_stream.send(method_name, *args) { |portion| @buffer << portion }
140
- end
141
-
142
- # -- common --
143
-
144
- protected def transcode(data)
145
- data = data.encode @external_encoding, **@transcode_options unless @external_encoding.nil?
146
- data
147
- end
10
+ # LZWS::Stream::Writer class.
11
+ class Writer < ADSP::Stream::Writer
12
+ # Current raw stream class.
13
+ RawCompressor = Raw::Compressor
148
14
  end
149
15
  end
150
16
  end
data/lib/lzws/string.rb CHANGED
@@ -1,29 +1,25 @@
1
1
  # Ruby bindings for lzws library.
2
2
  # Copyright (c) 2019 AUTHORS, MIT License.
3
3
 
4
+ require "adsp/string"
4
5
  require "lzws_ext"
5
6
 
6
7
  require_relative "option"
7
- require_relative "validation"
8
8
 
9
9
  module LZWS
10
- module String
11
- BUFFER_LENGTH_NAMES = %i[destination_buffer_length].freeze
12
-
13
- def self.compress(source, options = {})
14
- Validation.validate_string source
15
-
16
- options = Option.get_compressor_options options, BUFFER_LENGTH_NAMES
17
-
18
- LZWS._native_compress_string source, options
10
+ # LZWS::String class.
11
+ class String < ADSP::String
12
+ # Current option class.
13
+ Option = LZWS::Option
14
+
15
+ # Bypasses native compress.
16
+ def self.native_compress_string(*args)
17
+ LZWS._native_compress_string(*args)
19
18
  end
20
19
 
21
- def self.decompress(source, options = {})
22
- Validation.validate_string source
23
-
24
- options = Option.get_decompressor_options options, BUFFER_LENGTH_NAMES
25
-
26
- LZWS._native_decompress_string source, options
20
+ # Bypasses native decompress.
21
+ def self.native_decompress_string(*args)
22
+ LZWS._native_decompress_string(*args)
27
23
  end
28
24
  end
29
25
  end
@@ -1,51 +1,14 @@
1
1
  # Ruby bindings for lzws library.
2
2
  # Copyright (c) 2019 AUTHORS, MIT License.
3
3
 
4
- require_relative "error"
4
+ require "adsp/validation"
5
5
 
6
6
  module LZWS
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
-
7
+ # LZWS::Validation class.
8
+ class Validation < ADSP::Validation
9
+ # Raises error when +value+ is not boolean.
21
10
  def self.validate_bool(value)
22
11
  raise ValidateError, "invalid bool" unless value.is_a?(::TrueClass) || value.is_a?(::FalseClass)
23
12
  end
24
-
25
- def self.validate_positive_integer(value)
26
- raise ValidateError, "invalid positive integer" unless value.is_a?(::Integer) && value.positive?
27
- end
28
-
29
- def self.validate_not_negative_integer(value)
30
- raise ValidateError, "invalid not negative integer" unless value.is_a?(::Integer) && value >= 0
31
- end
32
-
33
- def self.validate_string(value)
34
- raise ValidateError, "invalid string" unless value.is_a? ::String
35
- end
36
-
37
- def self.validate_io(value)
38
- raise ValidateError, "invalid io" unless IO_METHODS.all? { |method| value.respond_to? method }
39
- end
40
-
41
- def self.validate_hash(value)
42
- raise ValidateError, "invalid hash" unless value.is_a? ::Hash
43
- end
44
-
45
- def self.validate_proc(value)
46
- unless value.is_a?(::Proc) || value.is_a?(::Method) || value.is_a?(::UnboundMethod)
47
- raise ValidateError, "invalid proc"
48
- end
49
- end
50
13
  end
51
14
  end
data/lib/lzws/version.rb CHANGED
@@ -2,5 +2,5 @@
2
2
  # Copyright (c) 2019 AUTHORS, MIT License.
3
3
 
4
4
  module LZWS
5
- VERSION = "1.4.0".freeze
5
+ VERSION = "1.4.3".freeze
6
6
  end
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-lzws
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.0
4
+ version: 1.4.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Aladjev
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-09-30 00:00:00.000000000 Z
11
+ date: 2022-07-06 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: adsp
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.0'
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: codecov
15
29
  requirement: !ruby/object:Gem::Requirement
@@ -58,14 +72,14 @@ dependencies:
58
72
  requirements:
59
73
  - - "~>"
60
74
  - !ruby/object:Gem::Version
61
- version: '5.14'
75
+ version: '5.16'
62
76
  type: :development
63
77
  prerelease: false
64
78
  version_requirements: !ruby/object:Gem::Requirement
65
79
  requirements:
66
80
  - - "~>"
67
81
  - !ruby/object:Gem::Version
68
- version: '5.14'
82
+ version: '5.16'
69
83
  - !ruby/object:Gem::Dependency
70
84
  name: ocg
71
85
  requirement: !ruby/object:Gem::Requirement
@@ -122,48 +136,62 @@ dependencies:
122
136
  - - ">="
123
137
  - !ruby/object:Gem::Version
124
138
  version: '0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: rdoc
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
125
153
  - !ruby/object:Gem::Dependency
126
154
  name: rubocop
127
155
  requirement: !ruby/object:Gem::Requirement
128
156
  requirements:
129
157
  - - "~>"
130
158
  - !ruby/object:Gem::Version
131
- version: '1.22'
159
+ version: '1.31'
132
160
  type: :development
133
161
  prerelease: false
134
162
  version_requirements: !ruby/object:Gem::Requirement
135
163
  requirements:
136
164
  - - "~>"
137
165
  - !ruby/object:Gem::Version
138
- version: '1.22'
166
+ version: '1.31'
139
167
  - !ruby/object:Gem::Dependency
140
168
  name: rubocop-minitest
141
169
  requirement: !ruby/object:Gem::Requirement
142
170
  requirements:
143
171
  - - "~>"
144
172
  - !ruby/object:Gem::Version
145
- version: '0.15'
173
+ version: '0.20'
146
174
  type: :development
147
175
  prerelease: false
148
176
  version_requirements: !ruby/object:Gem::Requirement
149
177
  requirements:
150
178
  - - "~>"
151
179
  - !ruby/object:Gem::Version
152
- version: '0.15'
180
+ version: '0.20'
153
181
  - !ruby/object:Gem::Dependency
154
182
  name: rubocop-performance
155
183
  requirement: !ruby/object:Gem::Requirement
156
184
  requirements:
157
185
  - - "~>"
158
186
  - !ruby/object:Gem::Version
159
- version: '1.11'
187
+ version: '1.14'
160
188
  type: :development
161
189
  prerelease: false
162
190
  version_requirements: !ruby/object:Gem::Requirement
163
191
  requirements:
164
192
  - - "~>"
165
193
  - !ruby/object:Gem::Version
166
- version: '1.11'
194
+ version: '1.14'
167
195
  - !ruby/object:Gem::Dependency
168
196
  name: rubocop-rake
169
197
  requirement: !ruby/object:Gem::Requirement
@@ -225,23 +253,18 @@ files:
225
253
  - lib/lzws/error.rb
226
254
  - lib/lzws/file.rb
227
255
  - lib/lzws/option.rb
228
- - lib/lzws/stream/abstract.rb
229
- - lib/lzws/stream/delegates.rb
230
- - lib/lzws/stream/raw/abstract.rb
231
256
  - lib/lzws/stream/raw/compressor.rb
232
257
  - lib/lzws/stream/raw/decompressor.rb
233
258
  - lib/lzws/stream/reader.rb
234
- - lib/lzws/stream/reader_helpers.rb
235
- - lib/lzws/stream/stat.rb
236
259
  - lib/lzws/stream/writer.rb
237
- - lib/lzws/stream/writer_helpers.rb
238
260
  - lib/lzws/string.rb
239
261
  - lib/lzws/validation.rb
240
262
  - lib/lzws/version.rb
241
263
  homepage: https://github.com/andrew-aladev/ruby-lzws
242
264
  licenses:
243
265
  - MIT
244
- metadata: {}
266
+ metadata:
267
+ rubygems_mfa_required: 'true'
245
268
  post_install_message:
246
269
  rdoc_options: []
247
270
  require_paths:
@@ -250,14 +273,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
250
273
  requirements:
251
274
  - - ">="
252
275
  - !ruby/object:Gem::Version
253
- version: '2.5'
276
+ version: '2.6'
254
277
  required_rubygems_version: !ruby/object:Gem::Requirement
255
278
  requirements:
256
279
  - - ">="
257
280
  - !ruby/object:Gem::Version
258
281
  version: '0'
259
282
  requirements: []
260
- rubygems_version: 3.2.22
283
+ rubygems_version: 3.3.7
261
284
  signing_key:
262
285
  specification_version: 4
263
286
  summary: Ruby bindings for lzws library (compatible with UNIX compress).
@@ -1,152 +0,0 @@
1
- # Ruby bindings for lzws library.
2
- # Copyright (c) 2019 AUTHORS, MIT License.
3
-
4
- require_relative "delegates"
5
- require_relative "stat"
6
- require_relative "../error"
7
- require_relative "../validation"
8
-
9
- module LZWS
10
- module Stream
11
- class Abstract
12
- # Native stream is not seekable by design.
13
- # Related methods like "seek" and "pos=" can't be implemented.
14
-
15
- # It is not possible to maintain correspondance between bytes
16
- # consumed from source and bytes written to destination by design.
17
- # We will consume all source bytes and maintain buffer with remaining destination data.
18
-
19
- include Delegates
20
-
21
- attr_reader :io, :stat, :external_encoding, :internal_encoding, :transcode_options, :pos
22
-
23
- alias tell pos
24
-
25
- def initialize(io, options = {})
26
- @raw_stream = create_raw_stream
27
-
28
- Validation.validate_io io
29
- @io = io
30
-
31
- @stat = Stat.new @io.stat if @io.respond_to? :stat
32
-
33
- set_encoding options[:external_encoding], options[:internal_encoding], options[:transcode_options]
34
- reset_buffer
35
- reset_io_advise
36
-
37
- @pos = 0
38
- end
39
-
40
- # -- buffer --
41
-
42
- protected def reset_buffer
43
- @buffer = ::String.new :encoding => ::Encoding::BINARY
44
- end
45
-
46
- # -- advise --
47
-
48
- protected def reset_io_advise
49
- # Both compressor and decompressor need sequential io access.
50
- @io.advise :sequential if @io.respond_to? :advise
51
- rescue ::Errno::ESPIPE
52
- # ok
53
- end
54
-
55
- def advise
56
- # Noop
57
- nil
58
- end
59
-
60
- # -- encoding --
61
-
62
- def set_encoding(*args)
63
- external_encoding, internal_encoding, transcode_options = process_set_encoding_arguments(*args)
64
-
65
- set_target_encoding :@external_encoding, external_encoding
66
- set_target_encoding :@internal_encoding, internal_encoding
67
- @transcode_options = transcode_options
68
-
69
- self
70
- end
71
-
72
- protected def process_set_encoding_arguments(*args)
73
- external_encoding = args[0]
74
-
75
- unless external_encoding.nil? || external_encoding.is_a?(::Encoding)
76
- Validation.validate_string external_encoding
77
-
78
- # First argument can be "external_encoding:internal_encoding".
79
- match = %r{(.+?):(.+)}.match external_encoding
80
-
81
- unless match.nil?
82
- external_encoding = match[0]
83
- internal_encoding = match[1]
84
-
85
- transcode_options = args[1]
86
- Validation.validate_hash transcode_options unless transcode_options.nil?
87
-
88
- return [external_encoding, internal_encoding, transcode_options]
89
- end
90
- end
91
-
92
- internal_encoding = args[1]
93
- unless internal_encoding.nil? || internal_encoding.is_a?(::Encoding)
94
- Validation.validate_string internal_encoding
95
- end
96
-
97
- transcode_options = args[2]
98
- Validation.validate_hash transcode_options unless transcode_options.nil?
99
-
100
- [external_encoding, internal_encoding, transcode_options]
101
- end
102
-
103
- protected def set_target_encoding(name, value)
104
- unless value.nil? || value.is_a?(::Encoding)
105
- begin
106
- value = ::Encoding.find value
107
- rescue ::ArgumentError
108
- raise ValidateError, "invalid #{name} encoding"
109
- end
110
- end
111
-
112
- instance_variable_set name, value
113
- end
114
-
115
- protected def target_encoding
116
- return @internal_encoding unless @internal_encoding.nil?
117
- return @external_encoding unless @external_encoding.nil?
118
-
119
- ::Encoding::BINARY
120
- end
121
-
122
- # -- etc --
123
-
124
- def rewind
125
- @raw_stream = create_raw_stream
126
-
127
- @io.rewind if @io.respond_to? :rewind
128
-
129
- reset_buffer
130
- reset_io_advise
131
-
132
- @pos = 0
133
-
134
- 0
135
- end
136
-
137
- def close
138
- @io.close
139
-
140
- nil
141
- end
142
-
143
- def closed?
144
- @raw_stream.closed? && @io.closed?
145
- end
146
-
147
- def to_io
148
- self
149
- end
150
- end
151
- end
152
- end
@@ -1,36 +0,0 @@
1
- # Ruby bindings for lzws library.
2
- # Copyright (c) 2019 AUTHORS, MIT License.
3
-
4
- require "forwardable"
5
-
6
- module LZWS
7
- module Stream
8
- module Delegates
9
- DELEGATES = %i[
10
- autoclose=
11
- autoclose?
12
- binmode
13
- binmode?
14
- close_on_exec=
15
- close_on_exec?
16
- fcntl
17
- fdatasync
18
- fileno
19
- fsync
20
- ioctl
21
- isatty
22
- pid
23
- sync
24
- sync=
25
- to_i
26
- tty?
27
- ]
28
- .freeze
29
-
30
- def self.included(klass)
31
- klass.extend ::Forwardable
32
- klass.def_delegators :@io, *DELEGATES
33
- end
34
- end
35
- end
36
- end
@@ -1,63 +0,0 @@
1
- # Ruby bindings for lzws library.
2
- # Copyright (c) 2019 AUTHORS, MIT License.
3
-
4
- require "lzws_ext"
5
-
6
- require_relative "../../error"
7
- require_relative "../../validation"
8
-
9
- module LZWS
10
- module Stream
11
- module Raw
12
- class Abstract
13
- def initialize(native_stream)
14
- @native_stream = native_stream
15
- @is_closed = false
16
- end
17
-
18
- # -- write --
19
-
20
- def flush(&writer)
21
- do_not_use_after_close
22
-
23
- Validation.validate_proc writer
24
-
25
- write_result(&writer)
26
-
27
- nil
28
- end
29
-
30
- protected def more_destination(&writer)
31
- result_bytesize = write_result(&writer)
32
- raise NotEnoughDestinationError, "not enough destination" if result_bytesize.zero?
33
- end
34
-
35
- protected def write_result(&_writer)
36
- result = @native_stream.read_result
37
- yield result
38
-
39
- result.bytesize
40
- end
41
-
42
- # -- close --
43
-
44
- protected def do_not_use_after_close
45
- raise UsedAfterCloseError, "used after close" if closed?
46
- end
47
-
48
- def close(&writer)
49
- write_result(&writer)
50
-
51
- @native_stream.close
52
- @is_closed = true
53
-
54
- nil
55
- end
56
-
57
- def closed?
58
- @is_closed
59
- end
60
- end
61
- end
62
- end
63
- end