io-stream 0.9.1 → 0.10.0
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/readable.rb +19 -19
- data/lib/io/stream/version.rb +1 -1
- data/readme.md +4 -7
- data/releases.md +4 -0
- data.tar.gz.sig +0 -0
- metadata +1 -1
- 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: c9a2897049a042fc1a0ba9a45d3f5700375938c6983d2ad2752f68c98b187b0c
|
4
|
+
data.tar.gz: 7991aaf45961ca5ec63254a1f83dffa5af87a1b4950aa0d0484ea4d23b55f7f0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ee85bb6dd18c0281d3dbe0d3af1a8cb5379834e40666e0a77c813a372f05dea8dda255a29c0196517ca978860f0032ee15bfec89cfb8770c1a24416acfc1d189
|
7
|
+
data.tar.gz: 399269a7444a2763b7ef82f2dacc2954aa06e82e3859a88411f7291f6afc98949d93a5b2936fdc8a0d493df3c38ee216b40e9055017f8c9f6c5dd95fcfc6116c
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data/lib/io/stream/readable.rb
CHANGED
@@ -30,7 +30,7 @@ module IO::Stream
|
|
30
30
|
# @parameter maximum_read_size [Integer] The maximum size for read operations.
|
31
31
|
# @parameter block_size [Integer] Legacy parameter, use minimum_read_size instead.
|
32
32
|
def initialize(minimum_read_size: MINIMUM_READ_SIZE, maximum_read_size: MAXIMUM_READ_SIZE, block_size: nil, **, &block)
|
33
|
-
@
|
33
|
+
@finished = false
|
34
34
|
@read_buffer = StringBuffer.new
|
35
35
|
# Used as destination buffer for underlying reads.
|
36
36
|
@input_buffer = StringBuffer.new
|
@@ -72,7 +72,7 @@ module IO::Stream
|
|
72
72
|
end
|
73
73
|
|
74
74
|
if size
|
75
|
-
until @
|
75
|
+
until @finished or @read_buffer.bytesize >= size
|
76
76
|
# Compute the amount of data we need to read from the underlying stream:
|
77
77
|
read_size = size - @read_buffer.bytesize
|
78
78
|
|
@@ -80,7 +80,7 @@ module IO::Stream
|
|
80
80
|
fill_read_buffer(read_size > @minimum_read_size ? read_size : @minimum_read_size)
|
81
81
|
end
|
82
82
|
else
|
83
|
-
until @
|
83
|
+
until @finished
|
84
84
|
fill_read_buffer
|
85
85
|
end
|
86
86
|
|
@@ -114,7 +114,7 @@ module IO::Stream
|
|
114
114
|
end
|
115
115
|
end
|
116
116
|
|
117
|
-
if !@
|
117
|
+
if !@finished and @read_buffer.empty?
|
118
118
|
fill_read_buffer
|
119
119
|
end
|
120
120
|
|
@@ -134,7 +134,7 @@ module IO::Stream
|
|
134
134
|
return buffer
|
135
135
|
end
|
136
136
|
|
137
|
-
raise exception, "
|
137
|
+
raise exception, "Stream finished before reading enough data!"
|
138
138
|
end
|
139
139
|
|
140
140
|
# This is a compatibility shim for existing code that uses `readpartial`.
|
@@ -142,7 +142,7 @@ module IO::Stream
|
|
142
142
|
# @parameter buffer [String | Nil] An optional buffer to fill with data instead of allocating a new string.
|
143
143
|
# @returns [String] The data read from the stream.
|
144
144
|
def readpartial(size = nil, buffer = nil)
|
145
|
-
read_partial(size, buffer) or raise EOFError, "
|
145
|
+
read_partial(size, buffer) or raise EOFError, "Stream finished before reading enough data!"
|
146
146
|
end
|
147
147
|
|
148
148
|
# Find the index of a pattern in the read buffer, reading more data if needed.
|
@@ -222,7 +222,7 @@ module IO::Stream
|
|
222
222
|
# @returns [String] The data in the buffer without consuming it.
|
223
223
|
def peek(size = nil)
|
224
224
|
if size
|
225
|
-
until @
|
225
|
+
until @finished or @read_buffer.bytesize >= size
|
226
226
|
# Compute the amount of data we need to read from the underlying stream:
|
227
227
|
read_size = size - @read_buffer.bytesize
|
228
228
|
|
@@ -231,7 +231,7 @@ module IO::Stream
|
|
231
231
|
end
|
232
232
|
return @read_buffer[..([size, @read_buffer.size].min - 1)]
|
233
233
|
end
|
234
|
-
until (block_given? && yield(@read_buffer)) or @
|
234
|
+
until (block_given? && yield(@read_buffer)) or @finished
|
235
235
|
fill_read_buffer
|
236
236
|
end
|
237
237
|
return @read_buffer
|
@@ -287,33 +287,33 @@ module IO::Stream
|
|
287
287
|
# See {readable?} for a non-blocking alternative.
|
288
288
|
#
|
289
289
|
# @returns [Boolean] If the stream is at file which means there is no more data to be read.
|
290
|
-
def
|
290
|
+
def finished?
|
291
291
|
if !@read_buffer.empty?
|
292
292
|
return false
|
293
|
-
elsif @
|
293
|
+
elsif @finished
|
294
294
|
return true
|
295
295
|
else
|
296
296
|
return !self.fill_read_buffer
|
297
297
|
end
|
298
298
|
end
|
299
299
|
|
300
|
-
alias eof?
|
300
|
+
alias eof? finished?
|
301
301
|
|
302
|
-
# Mark the stream as
|
303
|
-
def
|
302
|
+
# Mark the stream as finished and raise `EOFError`.
|
303
|
+
def finish!
|
304
304
|
@read_buffer.clear
|
305
|
-
@
|
305
|
+
@finished = true
|
306
306
|
|
307
307
|
raise EOFError
|
308
308
|
end
|
309
309
|
|
310
|
-
alias eof!
|
310
|
+
alias eof! finish!
|
311
311
|
|
312
312
|
# Whether there is a chance that a read operation will succeed or not.
|
313
313
|
# @returns [Boolean] If the stream is readable, i.e. a `read` operation has a chance of success.
|
314
314
|
def readable?
|
315
315
|
# If we are at the end of the file, we can't read any more data:
|
316
|
-
if @
|
316
|
+
if @finished
|
317
317
|
return false
|
318
318
|
end
|
319
319
|
|
@@ -358,7 +358,7 @@ module IO::Stream
|
|
358
358
|
end
|
359
359
|
|
360
360
|
# else for both cases above:
|
361
|
-
@
|
361
|
+
@finished = true
|
362
362
|
return false
|
363
363
|
end
|
364
364
|
|
@@ -367,8 +367,8 @@ module IO::Stream
|
|
367
367
|
# @parameter buffer [String | Nil] An optional buffer to fill with data instead of allocating a new string.
|
368
368
|
# @returns [String | Nil] The consumed data, or nil if no data available.
|
369
369
|
def consume_read_buffer(size = nil, buffer = nil)
|
370
|
-
# If we are at
|
371
|
-
if @
|
370
|
+
# If we are at finished, and the read buffer is empty, we can't consume anything.
|
371
|
+
if @finished && @read_buffer.empty?
|
372
372
|
# Clear the buffer even when returning nil
|
373
373
|
if buffer
|
374
374
|
buffer.clear
|
data/lib/io/stream/version.rb
CHANGED
data/readme.md
CHANGED
@@ -12,6 +12,10 @@ Please see the [project documentation](https://socketry.github.io/io-stream) for
|
|
12
12
|
|
13
13
|
Please see the [project releases](https://socketry.github.io/io-streamreleases/index) for all releases.
|
14
14
|
|
15
|
+
### v0.10.0
|
16
|
+
|
17
|
+
- Rename `done?` to `finished?` for clarity and consistency.
|
18
|
+
|
15
19
|
### v0.9.1
|
16
20
|
|
17
21
|
- Fix EOF behavior to match Ruby IO semantics: `read()` returns empty string `""` at EOF while `read(size)` returns `nil` at EOF.
|
@@ -55,13 +59,6 @@ Please see the [project releases](https://socketry.github.io/io-streamreleases/i
|
|
55
59
|
- Add external test suite for better integration testing.
|
56
60
|
- Update dependencies and improve code style with RuboCop.
|
57
61
|
|
58
|
-
### v0.4.1
|
59
|
-
|
60
|
-
- Add compatibility fix for `SSLSocket` raising `EBADF` errors.
|
61
|
-
- Fix `IO#close` hang issue in certain scenarios.
|
62
|
-
- Add `#to_io` method to `IO::Stream::Buffered` for better compatibility.
|
63
|
-
- Modernize gem structure and dependencies.
|
64
|
-
|
65
62
|
## See Also
|
66
63
|
|
67
64
|
- [async-io](https://github.com/socketry/async-io) — Where this implementation originally came from.
|
data/releases.md
CHANGED
data.tar.gz.sig
CHANGED
Binary file
|
metadata
CHANGED
metadata.gz.sig
CHANGED
Binary file
|