io-stream 0.9.0 → 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 +30 -19
- data/lib/io/stream/version.rb +1 -1
- data/readme.md +8 -11
- data/releases.md +8 -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,9 +80,20 @@ 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
|
+
|
87
|
+
if buffer
|
88
|
+
buffer.replace(@read_buffer)
|
89
|
+
@read_buffer.clear
|
90
|
+
else
|
91
|
+
buffer = @read_buffer
|
92
|
+
@read_buffer = StringBuffer.new
|
93
|
+
end
|
94
|
+
|
95
|
+
# Read without size always returns a non-nil value, even if it is an empty string.
|
96
|
+
return buffer
|
86
97
|
end
|
87
98
|
|
88
99
|
return consume_read_buffer(size, buffer)
|
@@ -103,7 +114,7 @@ module IO::Stream
|
|
103
114
|
end
|
104
115
|
end
|
105
116
|
|
106
|
-
if !@
|
117
|
+
if !@finished and @read_buffer.empty?
|
107
118
|
fill_read_buffer
|
108
119
|
end
|
109
120
|
|
@@ -123,7 +134,7 @@ module IO::Stream
|
|
123
134
|
return buffer
|
124
135
|
end
|
125
136
|
|
126
|
-
raise exception, "
|
137
|
+
raise exception, "Stream finished before reading enough data!"
|
127
138
|
end
|
128
139
|
|
129
140
|
# This is a compatibility shim for existing code that uses `readpartial`.
|
@@ -131,7 +142,7 @@ module IO::Stream
|
|
131
142
|
# @parameter buffer [String | Nil] An optional buffer to fill with data instead of allocating a new string.
|
132
143
|
# @returns [String] The data read from the stream.
|
133
144
|
def readpartial(size = nil, buffer = nil)
|
134
|
-
read_partial(size, buffer) or raise EOFError, "
|
145
|
+
read_partial(size, buffer) or raise EOFError, "Stream finished before reading enough data!"
|
135
146
|
end
|
136
147
|
|
137
148
|
# Find the index of a pattern in the read buffer, reading more data if needed.
|
@@ -211,7 +222,7 @@ module IO::Stream
|
|
211
222
|
# @returns [String] The data in the buffer without consuming it.
|
212
223
|
def peek(size = nil)
|
213
224
|
if size
|
214
|
-
until @
|
225
|
+
until @finished or @read_buffer.bytesize >= size
|
215
226
|
# Compute the amount of data we need to read from the underlying stream:
|
216
227
|
read_size = size - @read_buffer.bytesize
|
217
228
|
|
@@ -220,7 +231,7 @@ module IO::Stream
|
|
220
231
|
end
|
221
232
|
return @read_buffer[..([size, @read_buffer.size].min - 1)]
|
222
233
|
end
|
223
|
-
until (block_given? && yield(@read_buffer)) or @
|
234
|
+
until (block_given? && yield(@read_buffer)) or @finished
|
224
235
|
fill_read_buffer
|
225
236
|
end
|
226
237
|
return @read_buffer
|
@@ -276,33 +287,33 @@ module IO::Stream
|
|
276
287
|
# See {readable?} for a non-blocking alternative.
|
277
288
|
#
|
278
289
|
# @returns [Boolean] If the stream is at file which means there is no more data to be read.
|
279
|
-
def
|
290
|
+
def finished?
|
280
291
|
if !@read_buffer.empty?
|
281
292
|
return false
|
282
|
-
elsif @
|
293
|
+
elsif @finished
|
283
294
|
return true
|
284
295
|
else
|
285
296
|
return !self.fill_read_buffer
|
286
297
|
end
|
287
298
|
end
|
288
299
|
|
289
|
-
alias eof?
|
300
|
+
alias eof? finished?
|
290
301
|
|
291
|
-
# Mark the stream as
|
292
|
-
def
|
302
|
+
# Mark the stream as finished and raise `EOFError`.
|
303
|
+
def finish!
|
293
304
|
@read_buffer.clear
|
294
|
-
@
|
305
|
+
@finished = true
|
295
306
|
|
296
307
|
raise EOFError
|
297
308
|
end
|
298
309
|
|
299
|
-
alias eof!
|
310
|
+
alias eof! finish!
|
300
311
|
|
301
312
|
# Whether there is a chance that a read operation will succeed or not.
|
302
313
|
# @returns [Boolean] If the stream is readable, i.e. a `read` operation has a chance of success.
|
303
314
|
def readable?
|
304
315
|
# If we are at the end of the file, we can't read any more data:
|
305
|
-
if @
|
316
|
+
if @finished
|
306
317
|
return false
|
307
318
|
end
|
308
319
|
|
@@ -347,7 +358,7 @@ module IO::Stream
|
|
347
358
|
end
|
348
359
|
|
349
360
|
# else for both cases above:
|
350
|
-
@
|
361
|
+
@finished = true
|
351
362
|
return false
|
352
363
|
end
|
353
364
|
|
@@ -356,8 +367,8 @@ module IO::Stream
|
|
356
367
|
# @parameter buffer [String | Nil] An optional buffer to fill with data instead of allocating a new string.
|
357
368
|
# @returns [String | Nil] The consumed data, or nil if no data available.
|
358
369
|
def consume_read_buffer(size = nil, buffer = nil)
|
359
|
-
# If we are at
|
360
|
-
if @
|
370
|
+
# If we are at finished, and the read buffer is empty, we can't consume anything.
|
371
|
+
if @finished && @read_buffer.empty?
|
361
372
|
# Clear the buffer even when returning nil
|
362
373
|
if buffer
|
363
374
|
buffer.clear
|
data/lib/io/stream/version.rb
CHANGED
data/readme.md
CHANGED
@@ -12,6 +12,14 @@ 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
|
+
|
19
|
+
### v0.9.1
|
20
|
+
|
21
|
+
- Fix EOF behavior to match Ruby IO semantics: `read()` returns empty string `""` at EOF while `read(size)` returns `nil` at EOF.
|
22
|
+
|
15
23
|
### v0.9.0
|
16
24
|
|
17
25
|
- Add support for `buffer` parameter in `read`, `read_exactly`, and `read_partial` methods to allow reading into a provided buffer.
|
@@ -51,17 +59,6 @@ Please see the [project releases](https://socketry.github.io/io-streamreleases/i
|
|
51
59
|
- Add external test suite for better integration testing.
|
52
60
|
- Update dependencies and improve code style with RuboCop.
|
53
61
|
|
54
|
-
### v0.4.1
|
55
|
-
|
56
|
-
- Add compatibility fix for `SSLSocket` raising `EBADF` errors.
|
57
|
-
- Fix `IO#close` hang issue in certain scenarios.
|
58
|
-
- Add `#to_io` method to `IO::Stream::Buffered` for better compatibility.
|
59
|
-
- Modernize gem structure and dependencies.
|
60
|
-
|
61
|
-
### v0.4.0
|
62
|
-
|
63
|
-
- Add convenient `IO.Stream()` constructor method for creating buffered streams.
|
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
@@ -1,5 +1,13 @@
|
|
1
1
|
# Releases
|
2
2
|
|
3
|
+
## v0.10.0
|
4
|
+
|
5
|
+
- Rename `done?` to `finished?` for clarity and consistency.
|
6
|
+
|
7
|
+
## v0.9.1
|
8
|
+
|
9
|
+
- Fix EOF behavior to match Ruby IO semantics: `read()` returns empty string `""` at EOF while `read(size)` returns `nil` at EOF.
|
10
|
+
|
3
11
|
## v0.9.0
|
4
12
|
|
5
13
|
- Add support for `buffer` parameter in `read`, `read_exactly`, and `read_partial` methods to allow reading into a provided buffer.
|
data.tar.gz.sig
CHANGED
Binary file
|
metadata
CHANGED
metadata.gz.sig
CHANGED
Binary file
|