io-stream 0.4.0 → 0.4.2
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.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/lib/io/stream/buffered.rb +17 -4
- data/lib/io/stream/generic.rb +37 -29
- data/lib/io/stream/openssl.rb +1 -1
- data/lib/io/stream/shim/buffered.rb +2 -2
- data/lib/io/stream/shim/readable.rb +3 -3
- data/lib/io/stream/shim/timeout.rb +3 -0
- data/lib/io/stream/version.rb +1 -1
- data/lib/io/stream.rb +2 -2
- data/readme.md +3 -3
- data.tar.gz.sig +0 -0
- metadata +3 -3
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fe1cb88a44b5750ca8841631a3031da7ff06004e21d5dccf319012f0a0f1151f
|
4
|
+
data.tar.gz: 30d66da77b2887c16024511e907a8b30fdf1b24c53ee548f3a9171b54ff45ee1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e2ad4475b779c7c421fb7143fac491243790e210c12dac89d37e885753353c78d1305bd08144e12204a13d4c068c7cf16a9133462fe0a5f19a5eecd49e839fc7
|
7
|
+
data.tar.gz: edef464bbf54fdfd662850aca4b7fcc522caca32566a2201b2ee8c68460c5eff9ae67d5e645e255b2e60ba951b88d10703648393e65c4f1b58f12ccffc8cd6cb
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data/lib/io/stream/buffered.rb
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
# Released under the MIT License.
|
4
4
|
# Copyright, 2024, by Samuel Williams.
|
5
5
|
|
6
|
-
require_relative
|
6
|
+
require_relative "generic"
|
7
7
|
|
8
8
|
module IO::Stream
|
9
9
|
class Buffered < Generic
|
@@ -22,7 +22,7 @@ module IO::Stream
|
|
22
22
|
def self.wrap(io, **options)
|
23
23
|
if io.respond_to?(:buffered=)
|
24
24
|
io.buffered = false
|
25
|
-
|
25
|
+
elsif io.respond_to?(:sync=)
|
26
26
|
io.sync = true
|
27
27
|
end
|
28
28
|
|
@@ -50,6 +50,10 @@ module IO::Stream
|
|
50
50
|
|
51
51
|
attr :io
|
52
52
|
|
53
|
+
def to_io
|
54
|
+
@io.to_io
|
55
|
+
end
|
56
|
+
|
53
57
|
def closed?
|
54
58
|
@io.closed?
|
55
59
|
end
|
@@ -70,8 +74,15 @@ module IO::Stream
|
|
70
74
|
|
71
75
|
protected
|
72
76
|
|
73
|
-
|
74
|
-
|
77
|
+
if RUBY_VERSION >= "3.3.0"
|
78
|
+
def sysclose
|
79
|
+
# https://bugs.ruby-lang.org/issues/20723
|
80
|
+
Thread.new{@io.close}.join
|
81
|
+
end
|
82
|
+
else
|
83
|
+
def sysclose
|
84
|
+
@io.close
|
85
|
+
end
|
75
86
|
end
|
76
87
|
|
77
88
|
def syswrite(buffer)
|
@@ -111,6 +122,8 @@ module IO::Stream
|
|
111
122
|
return result
|
112
123
|
end
|
113
124
|
end
|
125
|
+
rescue Errno::EBADF
|
126
|
+
raise ::IOError, "stream closed"
|
114
127
|
end
|
115
128
|
end
|
116
129
|
end
|
data/lib/io/stream/generic.rb
CHANGED
@@ -3,20 +3,20 @@
|
|
3
3
|
# Released under the MIT License.
|
4
4
|
# Copyright, 2023-2024, by Samuel Williams.
|
5
5
|
|
6
|
-
require_relative
|
6
|
+
require_relative "string_buffer"
|
7
7
|
|
8
|
-
require_relative
|
9
|
-
require_relative
|
10
|
-
require_relative
|
8
|
+
require_relative "shim/buffered"
|
9
|
+
require_relative "shim/readable"
|
10
|
+
require_relative "shim/timeout"
|
11
11
|
|
12
|
-
require_relative
|
12
|
+
require_relative "openssl"
|
13
13
|
|
14
14
|
module IO::Stream
|
15
15
|
# The default block size for IO buffers. Defaults to 64KB (typical pipe buffer size).
|
16
|
-
BLOCK_SIZE = ENV.fetch(
|
16
|
+
BLOCK_SIZE = ENV.fetch("IO_STREAM_BLOCK_SIZE", 1024*64).to_i
|
17
17
|
|
18
18
|
# The maximum read size when appending to IO buffers. Defaults to 8MB.
|
19
|
-
MAXIMUM_READ_SIZE = ENV.fetch(
|
19
|
+
MAXIMUM_READ_SIZE = ENV.fetch("IO_STREAM_MAXIMUM_READ_SIZE", BLOCK_SIZE * 128).to_i
|
20
20
|
|
21
21
|
class Generic
|
22
22
|
def initialize(block_size: BLOCK_SIZE, maximum_read_size: MAXIMUM_READ_SIZE)
|
@@ -29,7 +29,6 @@ module IO::Stream
|
|
29
29
|
|
30
30
|
@read_buffer = StringBuffer.new
|
31
31
|
@write_buffer = StringBuffer.new
|
32
|
-
@drain_buffer = StringBuffer.new
|
33
32
|
|
34
33
|
# Used as destination buffer for underlying reads.
|
35
34
|
@input_buffer = StringBuffer.new
|
@@ -129,20 +128,21 @@ module IO::Stream
|
|
129
128
|
read_until(separator, **options)
|
130
129
|
end
|
131
130
|
|
131
|
+
private def drain(buffer)
|
132
|
+
begin
|
133
|
+
syswrite(buffer)
|
134
|
+
ensure
|
135
|
+
# If the write operation fails, we still need to clear this buffer, and the data is essentially lost.
|
136
|
+
buffer.clear
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
132
140
|
# Flushes buffered data to the stream.
|
133
141
|
def flush
|
134
142
|
return if @write_buffer.empty?
|
135
143
|
|
136
144
|
@writing.synchronize do
|
137
|
-
|
138
|
-
@write_buffer, @drain_buffer = @drain_buffer, @write_buffer
|
139
|
-
|
140
|
-
begin
|
141
|
-
syswrite(@drain_buffer)
|
142
|
-
ensure
|
143
|
-
# If the write operation fails, we still need to clear this buffer, and the data is essentially lost.
|
144
|
-
@drain_buffer.clear
|
145
|
-
end
|
145
|
+
self.drain(@write_buffer)
|
146
146
|
end
|
147
147
|
end
|
148
148
|
|
@@ -150,11 +150,15 @@ module IO::Stream
|
|
150
150
|
# buffer is flushed to the underlying `io`.
|
151
151
|
# @param string the string to write to the buffer.
|
152
152
|
# @return the number of bytes appended to the buffer.
|
153
|
-
def write(string)
|
154
|
-
@
|
155
|
-
|
156
|
-
|
157
|
-
flush
|
153
|
+
def write(string, flush: false)
|
154
|
+
@writing.synchronize do
|
155
|
+
@write_buffer << string
|
156
|
+
|
157
|
+
flush |= @write_buffer.bytesize >= @block_size
|
158
|
+
|
159
|
+
if flush
|
160
|
+
self.drain(@write_buffer)
|
161
|
+
end
|
158
162
|
end
|
159
163
|
|
160
164
|
return string.bytesize
|
@@ -168,11 +172,15 @@ module IO::Stream
|
|
168
172
|
end
|
169
173
|
|
170
174
|
def puts(*arguments, separator: $/)
|
171
|
-
arguments.
|
172
|
-
@write_buffer << argument << separator
|
173
|
-
end
|
175
|
+
return if arguments.empty?
|
174
176
|
|
175
|
-
|
177
|
+
@writing.synchronize do
|
178
|
+
arguments.each do |argument|
|
179
|
+
@write_buffer << argument << separator
|
180
|
+
end
|
181
|
+
|
182
|
+
self.drain(@write_buffer)
|
183
|
+
end
|
176
184
|
end
|
177
185
|
|
178
186
|
def closed?
|
@@ -195,7 +203,7 @@ module IO::Stream
|
|
195
203
|
rescue
|
196
204
|
# We really can't do anything here unless we want #close to raise exceptions.
|
197
205
|
ensure
|
198
|
-
sysclose
|
206
|
+
self.sysclose
|
199
207
|
end
|
200
208
|
end
|
201
209
|
|
@@ -266,13 +274,13 @@ module IO::Stream
|
|
266
274
|
|
267
275
|
if @read_buffer.empty?
|
268
276
|
if sysread(size, @read_buffer)
|
269
|
-
# Console.
|
277
|
+
# Console.info(self, name: "read") {@read_buffer.inspect}
|
270
278
|
return true
|
271
279
|
end
|
272
280
|
else
|
273
281
|
if chunk = sysread(size, @input_buffer)
|
274
282
|
@read_buffer << chunk
|
275
|
-
# Console.
|
283
|
+
# Console.info(self, name: "read") {@read_buffer.inspect}
|
276
284
|
|
277
285
|
return true
|
278
286
|
end
|
data/lib/io/stream/openssl.rb
CHANGED
@@ -15,7 +15,7 @@ unless IO.method_defined?(:buffered?, false)
|
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
18
|
-
require
|
18
|
+
require "socket"
|
19
19
|
|
20
20
|
unless BasicSocket.method_defined?(:buffered?, false)
|
21
21
|
class BasicSocket
|
@@ -50,7 +50,7 @@ unless BasicSocket.method_defined?(:buffered?, false)
|
|
50
50
|
end
|
51
51
|
end
|
52
52
|
|
53
|
-
require
|
53
|
+
require "stringio"
|
54
54
|
|
55
55
|
unless StringIO.method_defined?(:buffered?, false)
|
56
56
|
class StringIO
|
@@ -12,7 +12,7 @@ class IO
|
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
15
|
-
require
|
15
|
+
require "socket"
|
16
16
|
|
17
17
|
class BasicSocket
|
18
18
|
unless method_defined?(:readable?, false)
|
@@ -32,7 +32,7 @@ class BasicSocket
|
|
32
32
|
end
|
33
33
|
end
|
34
34
|
|
35
|
-
require
|
35
|
+
require "stringio"
|
36
36
|
|
37
37
|
class StringIO
|
38
38
|
unless method_defined?(:readable?, false)
|
@@ -42,7 +42,7 @@ class StringIO
|
|
42
42
|
end
|
43
43
|
end
|
44
44
|
|
45
|
-
require
|
45
|
+
require "openssl"
|
46
46
|
|
47
47
|
class OpenSSL::SSL::SSLSocket
|
48
48
|
unless method_defined?(:readable?, false)
|
data/lib/io/stream/version.rb
CHANGED
data/lib/io/stream.rb
CHANGED
data/readme.md
CHANGED
@@ -20,11 +20,11 @@ We welcome contributions to this project.
|
|
20
20
|
|
21
21
|
### Developer Certificate of Origin
|
22
22
|
|
23
|
-
|
23
|
+
In order to protect users of this project, we require all contributors to comply with the [Developer Certificate of Origin](https://developercertificate.org/). This ensures that all contributions are properly licensed and attributed.
|
24
24
|
|
25
|
-
###
|
25
|
+
### Community Guidelines
|
26
26
|
|
27
|
-
This project is
|
27
|
+
This project is best served by a collaborative and respectful environment. Treat each other professionally, respect differing viewpoints, and engage constructively. Harassment, discrimination, or harmful behavior is not tolerated. Communicate clearly, listen actively, and support one another. If any issues arise, please inform the project maintainers.
|
28
28
|
|
29
29
|
## See Also
|
30
30
|
|
data.tar.gz.sig
CHANGED
Binary file
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: io-stream
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Samuel Williams
|
@@ -37,7 +37,7 @@ cert_chain:
|
|
37
37
|
Q2K9NVun/S785AP05vKkXZEFYxqG6EW012U4oLcFl5MySFajYXRYbuUpH6AY+HP8
|
38
38
|
voD0MPg1DssDLKwXyt1eKD/+Fq0bFWhwVM/1XiAXL7lyYUyOq24KHgQ2Csg=
|
39
39
|
-----END CERTIFICATE-----
|
40
|
-
date: 2024-
|
40
|
+
date: 2024-10-01 00:00:00.000000000 Z
|
41
41
|
dependencies: []
|
42
42
|
description:
|
43
43
|
email:
|
@@ -78,7 +78,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
78
78
|
- !ruby/object:Gem::Version
|
79
79
|
version: '0'
|
80
80
|
requirements: []
|
81
|
-
rubygems_version: 3.5.
|
81
|
+
rubygems_version: 3.5.11
|
82
82
|
signing_key:
|
83
83
|
specification_version: 4
|
84
84
|
summary: Provides a generic stream wrapper for IO instances.
|
metadata.gz.sig
CHANGED
Binary file
|