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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 108295b1d28ce05e7c9e9e3f7b3d26427f564a85527a9f23a24ad5b47a261dea
4
- data.tar.gz: 2aa1c2f6d600d38667e5030122aecd1faa97f81be44695edf6776dda541d5a89
3
+ metadata.gz: c9a2897049a042fc1a0ba9a45d3f5700375938c6983d2ad2752f68c98b187b0c
4
+ data.tar.gz: 7991aaf45961ca5ec63254a1f83dffa5af87a1b4950aa0d0484ea4d23b55f7f0
5
5
  SHA512:
6
- metadata.gz: c6c9fc15b84c0ef6d58e2400aeebaac0a36fd67f656dcf10e2f4a1dde2176434dc8f9464809f2b5c05af2563c8bcb1a74ef1e243b7263348d36d24f00df2af7c
7
- data.tar.gz: 92c3a90776a6f6308ab7d0fa25d35b7df65021f70cb8aadf01e7363961c818392c2ce3fe861b20b38965acebcca851e7419708ad18b2536ae892496b9ea39ade
6
+ metadata.gz: ee85bb6dd18c0281d3dbe0d3af1a8cb5379834e40666e0a77c813a372f05dea8dda255a29c0196517ca978860f0032ee15bfec89cfb8770c1a24416acfc1d189
7
+ data.tar.gz: 399269a7444a2763b7ef82f2dacc2954aa06e82e3859a88411f7291f6afc98949d93a5b2936fdc8a0d493df3c38ee216b40e9055017f8c9f6c5dd95fcfc6116c
checksums.yaml.gz.sig CHANGED
Binary file
@@ -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
- @done = false
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 @done or @read_buffer.bytesize >= size
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 @done
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 !@done and @read_buffer.empty?
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, "Encountered done while reading data!"
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, "Encountered done while reading data!"
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 @done or @read_buffer.bytesize >= size
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 @done
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 done?
290
+ def finished?
280
291
  if !@read_buffer.empty?
281
292
  return false
282
- elsif @done
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? done?
300
+ alias eof? finished?
290
301
 
291
- # Mark the stream as done and raise `EOFError`.
292
- def done!
302
+ # Mark the stream as finished and raise `EOFError`.
303
+ def finish!
293
304
  @read_buffer.clear
294
- @done = true
305
+ @finished = true
295
306
 
296
307
  raise EOFError
297
308
  end
298
309
 
299
- alias eof! done!
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 @done
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
- @done = true
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 done, and the read buffer is empty, we can't consume anything.
360
- if @done && @read_buffer.empty?
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
@@ -4,5 +4,5 @@
4
4
  # Copyright, 2023-2024, by Samuel Williams.
5
5
 
6
6
  module IO::Stream
7
- VERSION = "0.9.0"
7
+ VERSION = "0.10.0"
8
8
  end
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
@@ -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.9.0
4
+ version: 0.10.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams
metadata.gz.sig CHANGED
Binary file