8000 Add functionality to be able to peek `n` bytes off the wire by maruth-stripe · Pull Request #72 · socketry/async-io · GitHub
[go: up one dir, main page]

Skip to content
This repository was archived by the owner on Aug 29, 2024. It is now read-only.

Add functionality to be able to peek n bytes off the wire #72

Merged
merged 5 commits into from
Nov 9, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Fix tests
  • Loading branch information
maruth-stripe authored and ioquatix committed Nov 9, 2023
commit ed42fcdb18dfd1026ec2af270dd25150592f730b
1 change: 1 addition & 0 deletions lib/async/io/stream.rb
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ def peek(size = nil)
until (block_given? && yield(@read_buffer)) or @eof
fill_read_buffer
end
return @read_buffer
end

def gets(separator = $/, **options)
Expand Down
2 changes: 1 addition & 1 deletion spec/async/io/stream_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@
io.write "Hello World"
io.seek(0)

expect(subject.io).to receive(:read_nonblock).and_call_original.once
expect(subject.io).to receive(:read_nonblock).and_call_original.twice

expect(subject.peek(4)).to be == "Hell"
expect(subject.read_partial(4)).to be == "Hell"
Expand Down
0