Class: LLM::Multipart::EnumeratorIO
- Inherits:
-
Object
- Object
- LLM::Multipart::EnumeratorIO
- Defined in:
- lib/llm/multipart/enumerator_io.rb
Overview
Wraps an Enumerator as an IO-like object for streaming bodies.
Instance Method Summary collapse
-
#eof? ⇒ Boolean
Returns true when no more data is available.
-
#initialize(enum) ⇒ EnumeratorIO
constructor
A new instance of EnumeratorIO.
-
#read(length = nil, outbuf = +"")) ⇒ String?
Reads bytes from the stream.
-
#rewind ⇒ Object
Raises when called, the stream is not rewindable.
Constructor Details
#initialize(enum) ⇒ EnumeratorIO
Returns a new instance of EnumeratorIO.
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
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
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 |
#rewind ⇒ Object
Raises when called, the stream is not rewindable
44 45 46 |
# File 'lib/llm/multipart/enumerator_io.rb', line 44 def rewind raise IOError, "stream is not rewindable" end |