Class: Anthropic::Internal::Util::ReadIOAdapter Private
- Inherits:
-
Object
- Object
- Anthropic::Internal::Util::ReadIOAdapter
- Defined in:
- lib/anthropic/internal/util.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
An adapter that satisfies the IO interface required by ‘::IO.copy_stream`
Instance Method Summary collapse
- #close ⇒ Object private
- #close? ⇒ Boolean? private
-
#initialize(src, &blk) {|| ... } ⇒ ReadIOAdapter
constructor
private
A new instance of ReadIOAdapter.
- #read(max_len = nil, out_string = nil) ⇒ String? private
Constructor Details
#initialize(src, &blk) {|| ... } ⇒ ReadIOAdapter
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of ReadIOAdapter.
500 501 502 503 504 505 506 507 508 509 510 511 512 513 |
# File 'lib/anthropic/internal/util.rb', line 500 def initialize(src, &blk) @stream = case src in String StringIO.new(src) in Pathname @closing = true src.open(binmode: true) else src end @buf = String.new @blk = blk end |
Instance Method Details
#close ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
442 443 444 445 446 447 448 449 450 |
# File 'lib/anthropic/internal/util.rb', line 442 def close case @stream in Enumerator Anthropic::Internal::Util.close_fused!(@stream) in IO if close? @stream.close else end end |
#close? ⇒ Boolean?
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
439 |
# File 'lib/anthropic/internal/util.rb', line 439 def close? = @closing |
#read(max_len = nil, out_string = nil) ⇒ String?
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 |
# File 'lib/anthropic/internal/util.rb', line 476 def read(max_len = nil, out_string = nil) case @stream in nil nil in IO | StringIO @stream.read(max_len, out_string) in Enumerator read = read_enum(max_len) case out_string in String out_string.replace(read) in nil read end end .tap(&@blk) end |