Class: LLM::Multipart::EnumeratorIO

Inherits:
Object
  • Object
show all
Defined in:
lib/llm/multipart/enumerator_io.rb

Overview

Wraps an Enumerator as an IO-like object for streaming bodies.

Instance Method Summary collapse

Constructor Details

#initialize(enum) ⇒ EnumeratorIO

Returns a new instance of EnumeratorIO.

Parameters:

  • enum (Enumerator)

    The enumerator yielding body chunks



11
12
13
14
15
# File 'lib/llm/multipart/enumerator_io.rb', line 11

def initialize(enum)
  @enum = enum
  @buffer = +""
  @eof = false
end

Instance Method Details

#eof?Boolean

Returns true when no more data is available

Returns:

  • (Boolean)


37
38
39
# File 'lib/llm/multipart/enumerator_io.rb', line 37

def eof?
  @eof && @buffer.empty?
end

#read(length = nil, outbuf = +"")) ⇒ String?

Reads bytes from the stream

Parameters:

  • length (Integer, nil) (defaults to: nil)

    The number of bytes to read (all when nil)

  • outbuf (String) (defaults to: +""))

    The buffer to fill

Returns:

  • (String, nil)

    Returns the data read, or nil on EOF



25
26
27
28
29
30
31
32
# File 'lib/llm/multipart/enumerator_io.rb', line 25

def read(length = nil, outbuf = +"")
  outbuf.clear
  if length.nil?
    read_all(outbuf)
  else
    read_chunk(length, outbuf)
  end
end

#rewindObject

Raises when called, the stream is not rewindable

Raises:

  • (IOError)


44
45
46
# File 'lib/llm/multipart/enumerator_io.rb', line 44

def rewind
  raise IOError, "stream is not rewindable"
end