File tree 2 files changed +26
-6
lines changed
2 files changed +26
-6
lines changed Original file line number Diff line number Diff line change @@ -89,12 +89,22 @@ def read(length = nil, buffer = nil)
89
89
# Will avoid reading from the underlying stream if there is buffered data available.
90
90
#
91
91
# @parameter length [Integer] The maximum number of bytes to read.
92
- def read_partial ( length = nil )
92
+ def read_partial ( length = nil , buffer = nil )
93
93
if @buffer
94
- buffer = @buffer
95
- @buffer = nil
94
+ if buffer
95
+ buffer . replace ( @buffer )
96
+ else
97
+ buffer = @buffer
98
+ @buffer = nil
99
+ end
96
100
else
97
- buffer = read_next
101
+ chunk = read_next
102
+
103
+ if buffer and chunk
104
+ buffer . replace ( chunk )
105
+ else
106
+ buffer = chunk
107
+ end
98
108
end
99
109
100
110
if buffer and length
@@ -111,8 +121,8 @@ def read_partial(length = nil)
111
121
end
112
122
113
123
# Similar to {read_partial} but raises an `EOFError` if the stream is at EOF.
114
- def readpartial ( length )
115
- read_partial ( length ) or raise EOFError , "End of file reached!"
124
+ def readpartial ( length , buffer = nil )
125
+ read_partial ( length , buffer ) or raise EOFError , "End of file reached!"
116
126
end
117
127
118
128
# Read data from the stream without blocking if possible.
Original file line number Diff line number Diff line change 224
224
expect ( stream ) . to be ( :closed? )
225
225
end
226
226
end
227
+
228
+ with 'IO.copy_stream' do
229
+ let ( :output ) { StringIO . new }
230
+
231
+ it "can copy input to output" do
232
+ ::IO . copy_stream ( stream , output )
233
+
234
+ expect ( output . string ) . to be == "HelloWorld"
235
+ end
236
+ end
227
237
end
You can’t perform that action at this time.
0 commit comments