ruby-lzws 1.4.1 → 1.4.2

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: 0cd332331b0c0eac3a21a008ec7796ffbee88d7b79039108f9e4857f5ed2a793
4
- data.tar.gz: 42f29271be355fe9e48a877a640391d21e8820fd34ca96975b07d063dc3e1abb
3
+ metadata.gz: 0e48df46a2a929a961d72881cf20a4c087769576f3208cc2dee02a31b3d1f00a
4
+ data.tar.gz: f5fe984d47acaa03d91ca5f7d19a5e87c49b029aea37323fbd2e2c72a5f57491
5
5
  SHA512:
6
- metadata.gz: 9545c057aee9de7e1528905d215c45fe15aa798d1f81dc03e418e1a9ae0b0669d17282d82997f33844563612f731b1ee87b744639b3d04b173d37b28bf492344
7
- data.tar.gz: a8eec9b071600eb5ff98efb53aefbf0c48779aa3e468b3c538916bf3335171eefe0e1a73b3d6de8385823e439bd939c6c033cafd5a7c281111f1b4a51b012645
6
+ metadata.gz: 3ea80697e381e1a350bb49c0c267791b41783e09ccfca10348ae1c02afa090de7930d06f1a2ca8fd6ff81929f86f34ff6bf46d9b51ac83fe4dc09c558227385c
7
+ data.tar.gz: 7c6843ea9729056bea5bd149b31d25409e9f5d225b43e12f6305353bf5a4b820eb94104e192d02dda454cccc0adf684e17dc953719184a7b5a846570f9575225
data/README.md CHANGED
@@ -8,7 +8,9 @@ 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.4.0+ version.
11
+ Operating systems: GNU/Linux, FreeBSD, OSX, Windows (MinGW).
12
+
13
+ Dependencies: [lzws](https://github.com/andrew-aladev/lzws) 1.4.0+ version.
12
14
 
13
15
  ```sh
14
16
  gem install ruby-lzws
@@ -354,10 +356,6 @@ You should lock all shared data between threads.
354
356
  For example: you should not use same compressor/decompressor inside multiple threads.
355
357
  Please verify that you are using each processor inside single thread at the same time.
356
358
 
357
- ## Operating systems
358
-
359
- GNU/Linux, FreeBSD, OSX, Windows (MinGW).
360
-
361
359
  ## CI
362
360
 
363
361
  Please visit [scripts/test-images](scripts/test-images).
data/ext/lzws_ext/gvl.h CHANGED
@@ -4,7 +4,7 @@
4
4
  #if !defined(LZWS_EXT_GVL_H)
5
5
  #define LZWS_EXT_GVL_H
6
6
 
7
- #ifdef HAVE_RB_THREAD_CALL_WITHOUT_GVL
7
+ #if defined(HAVE_RB_THREAD_CALL_WITHOUT_GVL)
8
8
 
9
9
  #include "ruby/thread.h"
10
10
 
@@ -19,6 +19,6 @@
19
19
 
20
20
  #define LZWS_EXT_GVL_WRAP(_gvl, function, data) function((void*) data);
21
21
 
22
- #endif
22
+ #endif // HAVE_RB_THREAD_CALL_WITHOUT_GVL
23
23
 
24
24
  #endif // LZWS_EXT_GVL_H
data/ext/lzws_ext/macro.h CHANGED
@@ -8,6 +8,6 @@
8
8
  #define LZWS_EXT_UNUSED(x) x __attribute__((__unused__))
9
9
  #else
10
10
  #define LZWS_EXT_UNUSED(x) x
11
- #endif
11
+ #endif // __GNUC__
12
12
 
13
13
  #endif // LZWS_EXT_MACRO_H
@@ -24,9 +24,7 @@ module LZWS
24
24
 
25
25
  def initialize(io, options = {})
26
26
  @raw_stream = create_raw_stream
27
-
28
- Validation.validate_io io
29
- @io = io
27
+ @io = io
30
28
 
31
29
  @stat = Stat.new @io.stat if @io.respond_to? :stat
32
30
 
@@ -135,13 +133,19 @@ module LZWS
135
133
  end
136
134
 
137
135
  def close
138
- @io.close
136
+ @io.close if @io.respond_to? :close
139
137
 
140
138
  nil
141
139
  end
142
140
 
143
141
  def closed?
144
- @raw_stream.closed? && @io.closed?
142
+ return false unless @raw_stream.closed?
143
+
144
+ if @io.respond_to? :closed
145
+ @io.closed?
146
+ else
147
+ true
148
+ end
145
149
  end
146
150
 
147
151
  def to_io
@@ -54,6 +54,9 @@ module LZWS
54
54
  Validation.validate_not_negative_integer bytes_to_read unless bytes_to_read.nil?
55
55
  Validation.validate_string out_buffer unless out_buffer.nil?
56
56
 
57
+ raise ValidateError, "io should be responsible to read and eof" unless
58
+ @io.respond_to?(:read) && @io.respond_to?(:eof?)
59
+
57
60
  unless bytes_to_read.nil?
58
61
  return ::String.new :encoding => ::Encoding::BINARY if bytes_to_read.zero?
59
62
  return nil if eof?
@@ -86,16 +89,22 @@ module LZWS
86
89
  end
87
90
 
88
91
  def eof?
92
+ raise ValidateError, "io should be responsible to eof" unless @io.respond_to? :eof?
93
+
89
94
  empty? && @io.eof?
90
95
  end
91
96
 
92
97
  # -- asynchronous --
93
98
 
94
99
  def readpartial(bytes_to_read, out_buffer = nil)
100
+ raise ValidateError, "io should be responsible to readpartial" unless @io.respond_to? :readpartial
101
+
95
102
  read_more_nonblock(bytes_to_read, out_buffer) { @io.readpartial @source_buffer_length }
96
103
  end
97
104
 
98
105
  def read_nonblock(bytes_to_read, out_buffer = nil, *options)
106
+ raise ValidateError, "io should be responsible to read nonblock" unless @io.respond_to? :read_nonblock
107
+
99
108
  read_more_nonblock(bytes_to_read, out_buffer) { @io.read_nonblock(@source_buffer_length, *options) }
100
109
  end
101
110
 
@@ -23,6 +23,8 @@ module LZWS
23
23
  # -- synchronous --
24
24
 
25
25
  def write(*objects)
26
+ validate_write
27
+
26
28
  write_remaining_buffer
27
29
 
28
30
  bytes_written = 0
@@ -38,20 +40,26 @@ module LZWS
38
40
  end
39
41
 
40
42
  def flush
43
+ validate_write
44
+
41
45
  finish :flush
42
46
 
43
- @io.flush
47
+ @io.flush if @io.respond_to? :flush
44
48
 
45
49
  self
46
50
  end
47
51
 
48
52
  def rewind
53
+ validate_write
54
+
49
55
  finish :close
50
56
 
51
57
  super
52
58
  end
53
59
 
54
60
  def close
61
+ validate_write
62
+
55
63
  finish :close
56
64
 
57
65
  super
@@ -75,6 +83,10 @@ module LZWS
75
83
  @raw_stream.send(method_name, *args) { |portion| @io.write portion }
76
84
  end
77
85
 
86
+ def validate_write
87
+ raise ValidateError, "io should be responsible to write" unless @io.respond_to? :write
88
+ end
89
+
78
90
  # -- asynchronous --
79
91
 
80
92
  # IO write nonblock can raise wait writable error.
@@ -83,6 +95,8 @@ module LZWS
83
95
  # So we have to accept content after processing IO write nonblock.
84
96
  # It means that first write nonblock won't call IO write nonblock.
85
97
  def write_nonblock(object, *options)
98
+ validate_write_nonblock
99
+
86
100
  return 0 unless write_remaining_buffer_nonblock(*options)
87
101
 
88
102
  source = transcode object.to_s
@@ -93,14 +107,18 @@ module LZWS
93
107
  end
94
108
 
95
109
  def flush_nonblock(*options)
110
+ validate_write_nonblock
111
+
96
112
  return false unless finish_nonblock :flush, *options
97
113
 
98
- @io.flush
114
+ @io.flush if @io.respond_to? :flush
99
115
 
100
116
  true
101
117
  end
102
118
 
103
119
  def rewind_nonblock(*options)
120
+ validate_write_nonblock
121
+
104
122
  return false unless finish_nonblock :close, *options
105
123
 
106
124
  method(:rewind).super_method.call
@@ -109,6 +127,8 @@ module LZWS
109
127
  end
110
128
 
111
129
  def close_nonblock(*options)
130
+ validate_write_nonblock
131
+
112
132
  return false unless finish_nonblock :close, *options
113
133
 
114
134
  method(:close).super_method.call
@@ -139,6 +159,10 @@ module LZWS
139
159
  @raw_stream.send(method_name, *args) { |portion| @buffer << portion }
140
160
  end
141
161
 
162
+ def validate_write_nonblock
163
+ raise ValidateError, "io should be responsible to write nonblock" unless @io.respond_to? :write_nonblock
164
+ end
165
+
142
166
  # -- common --
143
167
 
144
168
  protected def transcode(data)
@@ -5,41 +5,20 @@ 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
-
21
8
  def self.validate_bool(value)
22
9
  raise ValidateError, "invalid bool" unless value.is_a?(::TrueClass) || value.is_a?(::FalseClass)
23
10
  end
24
11
 
25
- def self.validate_positive_integer(value)
26
- raise ValidateError, "invalid positive integer" unless value.is_a?(::Integer) && value.positive?
12
+ def self.validate_hash(value)
13
+ raise ValidateError, "invalid hash" unless value.is_a? ::Hash
27
14
  end
28
15
 
29
16
  def self.validate_not_negative_integer(value)
30
17
  raise ValidateError, "invalid not negative integer" unless value.is_a?(::Integer) && value >= 0
31
18
  end
32
19
 
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
20
+ def self.validate_positive_integer(value)
21
+ raise ValidateError, "invalid positive integer" unless value.is_a?(::Integer) && value.positive?
43
22
  end
44
23
 
45
24
  def self.validate_proc(value)
@@ -47,5 +26,9 @@ module LZWS
47
26
  raise ValidateError, "invalid proc"
48
27
  end
49
28
  end
29
+
30
+ def self.validate_string(value)
31
+ raise ValidateError, "invalid string" unless value.is_a? ::String
32
+ end
50
33
  end
51
34
  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.1".freeze
5
+ VERSION = "1.4.2".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.4.1
4
+ version: 1.4.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: 2022-01-07 00:00:00.000000000 Z
11
+ date: 2022-03-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: codecov
@@ -128,14 +128,14 @@ dependencies:
128
128
  requirements:
129
129
  - - "~>"
130
130
  - !ruby/object:Gem::Version
131
- version: '1.24'
131
+ version: '1.26'
132
132
  type: :development
133
133
  prerelease: false
134
134
  version_requirements: !ruby/object:Gem::Requirement
135
135
  requirements:
136
136
  - - "~>"
137
137
  - !ruby/object:Gem::Version
138
- version: '1.24'
138
+ version: '1.26'
139
139
  - !ruby/object:Gem::Dependency
140
140
  name: rubocop-minitest
141
141
  requirement: !ruby/object:Gem::Requirement
@@ -258,7 +258,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
258
258
  - !ruby/object:Gem::Version
259
259
  version: '0'
260
260
  requirements: []
261
- rubygems_version: 3.3.3
261
+ rubygems_version: 3.3.7
262
262
  signing_key:
263
263
  specification_version: 4
264
264
  summary: Ruby bindings for lzws library (compatible with UNIX compress).