ruby-zstds 1.0.0 → 1.0.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,6 +1,8 @@
1
1
  # Ruby bindings for zstd library.
2
2
  # Copyright (c) 2019 AUTHORS, MIT License.
3
3
 
4
+ require "English"
5
+
4
6
  require_relative "../validation"
5
7
 
6
8
  module ZSTDS
@@ -64,7 +64,7 @@ module ZSTDS
64
64
  end
65
65
 
66
66
  protected def write_remaining_buffer
67
- return nil if @buffer.bytesize == 0
67
+ return nil if @buffer.bytesize.zero?
68
68
 
69
69
  @io.write @buffer
70
70
 
@@ -77,6 +77,11 @@ module ZSTDS
77
77
 
78
78
  # -- asynchronous --
79
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.
80
85
  def write_nonblock(object, *options)
81
86
  return 0 unless write_remaining_buffer_nonblock(*options)
82
87
 
@@ -120,14 +125,14 @@ module ZSTDS
120
125
  end
121
126
 
122
127
  protected def write_remaining_buffer_nonblock(*options)
123
- return true if @buffer.bytesize == 0
128
+ return true if @buffer.bytesize.zero?
124
129
 
125
130
  bytes_written = @io.write_nonblock @buffer, *options
126
- return false if bytes_written == 0
131
+ return false if bytes_written.zero?
127
132
 
128
133
  @buffer = @buffer.byteslice bytes_written, @buffer.bytesize - bytes_written
129
134
 
130
- @buffer.bytesize == 0
135
+ @buffer.bytesize.zero?
131
136
  end
132
137
 
133
138
  protected def raw_nonblock_wrapper(method_name, *args)
@@ -137,7 +142,7 @@ module ZSTDS
137
142
  # -- common --
138
143
 
139
144
  protected def transcode(data)
140
- data = data.encode @external_encoding, @transcode_options unless @external_encoding.nil?
145
+ data = data.encode @external_encoding, **@transcode_options unless @external_encoding.nil?
141
146
  data
142
147
  end
143
148
  end
@@ -1,6 +1,8 @@
1
1
  # Ruby bindings for zstd library.
2
2
  # Copyright (c) 2019 AUTHORS, MIT License.
3
3
 
4
+ require "English"
5
+
4
6
  require_relative "../error"
5
7
  require_relative "../validation"
6
8
 
@@ -11,18 +13,13 @@ module ZSTDS
11
13
  write object
12
14
  end
13
15
 
14
- def print(*objects)
15
- if objects.empty?
16
- write $LAST_READ_LINE unless $LAST_READ_LINE.nil?
17
- return nil
18
- end
19
-
16
+ def print(*objects, field_separator: $OUTPUT_FIELD_SEPARATOR, record_separator: $OUTPUT_RECORD_SEPARATOR)
20
17
  objects.each do |object|
21
18
  write object
22
- write $OUTPUT_FIELD_SEPARATOR unless $OUTPUT_FIELD_SEPARATOR.nil?
19
+ write field_separator unless field_separator.nil?
23
20
  end
24
21
 
25
- write $OUTPUT_RECORD_SEPARATOR unless $OUTPUT_RECORD_SEPARATOR.nil?
22
+ write record_separator unless record_separator.nil?
26
23
 
27
24
  nil
28
25
  end
@@ -34,9 +31,10 @@ module ZSTDS
34
31
  end
35
32
 
36
33
  def putc(object, encoding: ::Encoding::BINARY)
37
- if object.is_a? ::Numeric
34
+ case object
35
+ when ::Numeric
38
36
  write object.chr(encoding)
39
- elsif object.is_a? ::String
37
+ when ::String
40
38
  write object[0]
41
39
  else
42
40
  raise ValidateError, "invalid object: \"#{object}\" for putc"
@@ -5,6 +5,19 @@ require_relative "error"
5
5
 
6
6
  module ZSTDS
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
@@ -14,7 +27,7 @@ module ZSTDS
14
27
  end
15
28
 
16
29
  def self.validate_positive_integer(value)
17
- raise ValidateError, "invalid positive integer" unless value.is_a?(::Integer) && value > 0
30
+ raise ValidateError, "invalid positive integer" unless value.is_a?(::Integer) && value.positive?
18
31
  end
19
32
 
20
33
  def self.validate_not_negative_integer(value)
@@ -30,7 +43,7 @@ module ZSTDS
30
43
  end
31
44
 
32
45
  def self.validate_io(value)
33
- raise ValidateError, "invalid io" unless value.is_a? ::IO
46
+ raise ValidateError, "invalid io" unless IO_METHODS.all? { |method| value.respond_to? method }
34
47
  end
35
48
 
36
49
  def self.validate_array(value)
@@ -2,5 +2,5 @@
2
2
  # Copyright (c) 2019 AUTHORS, MIT License.
3
3
 
4
4
  module ZSTDS
5
- VERSION = "1.0.0".freeze
5
+ VERSION = "1.0.5".freeze
6
6
  end
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-zstds
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.5
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-11-13 00:00:00.000000000 Z
11
+ date: 2020-10-02 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: codecov
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: minitar
15
29
  requirement: !ruby/object:Gem::Requirement
@@ -52,20 +66,34 @@ dependencies:
52
66
  - - "~>"
53
67
  - !ruby/object:Gem::Version
54
68
  version: '1.1'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
55
83
  - !ruby/object:Gem::Dependency
56
84
  name: rake-compiler
57
85
  requirement: !ruby/object:Gem::Requirement
58
86
  requirements:
59
- - - "~>"
87
+ - - ">="
60
88
  - !ruby/object:Gem::Version
61
- version: '1.0'
89
+ version: '0'
62
90
  type: :development
63
91
  prerelease: false
64
92
  version_requirements: !ruby/object:Gem::Requirement
65
93
  requirements:
66
- - - "~>"
94
+ - - ">="
67
95
  - !ruby/object:Gem::Version
68
- version: '1.0'
96
+ version: '0'
69
97
  - !ruby/object:Gem::Dependency
70
98
  name: rubocop
71
99
  requirement: !ruby/object:Gem::Requirement
@@ -95,19 +123,19 @@ dependencies:
95
123
  - !ruby/object:Gem::Version
96
124
  version: '1.5'
97
125
  - !ruby/object:Gem::Dependency
98
- name: rubocop-rails
126
+ name: simplecov
99
127
  requirement: !ruby/object:Gem::Requirement
100
128
  requirements:
101
- - - "~>"
129
+ - - ">="
102
130
  - !ruby/object:Gem::Version
103
- version: '2.3'
131
+ version: '0'
104
132
  type: :development
105
133
  prerelease: false
106
134
  version_requirements: !ruby/object:Gem::Requirement
107
135
  requirements:
108
- - - "~>"
136
+ - - ">="
109
137
  - !ruby/object:Gem::Version
110
- version: '2.3'
138
+ version: '0'
111
139
  description:
112
140
  email: aladjev.andrew@gmail.com
113
141
  executables: []
@@ -166,16 +194,16 @@ require_paths:
166
194
  - lib
167
195
  required_ruby_version: !ruby/object:Gem::Requirement
168
196
  requirements:
169
- - - ">="
197
+ - - "~>"
170
198
  - !ruby/object:Gem::Version
171
- version: '0'
199
+ version: '2.7'
172
200
  required_rubygems_version: !ruby/object:Gem::Requirement
173
201
  requirements:
174
202
  - - ">="
175
203
  - !ruby/object:Gem::Version
176
204
  version: '0'
177
205
  requirements: []
178
- rubygems_version: 3.0.6
206
+ rubygems_version: 3.1.2
179
207
  signing_key:
180
208
  specification_version: 4
181
209
  summary: Ruby bindings for zstd library.