Class: Foam::Otel::LLM::HttpAnthropicShim::BufferedBodyStream

Inherits:
Object
  • Object
show all
Defined in:
lib/foam/otel/llm/http_anthropic_shim.rb

Overview

Matches HTTP::Connection's readpartial contract (nil at EOF, never EOFError) so a restored Body streams exactly like a live one.

Constant Summary collapse

CHUNK =
16_384

Instance Method Summary collapse

Constructor Details

#initialize(contents) ⇒ BufferedBodyStream

Returns a new instance of BufferedBodyStream.



221
222
223
# File 'lib/foam/otel/llm/http_anthropic_shim.rb', line 221

def initialize(contents)
  @io = StringIO.new(contents)
end

Instance Method Details

#readpartial(size = CHUNK, outbuf = nil) ⇒ Object



225
226
227
228
229
# File 'lib/foam/otel/llm/http_anthropic_shim.rb', line 225

def readpartial(size = CHUNK, outbuf = nil)
  return nil if @io.eof?

  outbuf ? @io.readpartial(size, outbuf) : @io.readpartial(size)
end