Skip to content

Commit 4461f75

Browse files
committed
Add support for #readpartial.
1 parent 1392355 commit 4461f75

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

lib/protocol/http/body/stream.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,8 @@ def read_partial(length = nil)
9898
return buffer
9999
end
100100

101-
def readpartial
102-
read_partial or raise EOFError, "End of file reached!"
101+
def readpartial(length)
102+
read_partial(length) or raise EOFError, "End of file reached!"
103103
end
104104

105105
def read_nonblock(length, buffer = nil)

test/protocol/http/body/stream.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,14 @@
123123
end
124124
end
125125

126+
with '#readpartial' do
127+
it "can read partial input" do
128+
expect(stream.readpartial(20)).to be == "Hello"
129+
expect(stream.readpartial(20)).to be == "World"
130+
expect{stream.readpartial(20)}.to raise_exception(EOFError)
131+
end
132+
end
133+
126134
with '#close_read' do
127135
it "should close the input" do
128136
stream.read(1)

0 commit comments

Comments
 (0)