Class: Anthropic::Internal::Util::ReadIOAdapter Private
- Inherits:
-
Object
- Object
- Anthropic::Internal::Util::ReadIOAdapter
- Defined in:
- lib/anthropic/internal/util.rb,
sig/anthropic/internal/util.rbs
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 ⇒ void private
- #close? ⇒ Boolean? private
-
#initialize(src, &blk) {|, arg0| ... } ⇒ ReadIOAdapter
constructor
private
A new instance of ReadIOAdapter.
- #read(max_len = nil, out_string = nil) ⇒ String? private
Constructor Details
#initialize(src, &blk) {|, arg0| ... } ⇒ 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.
531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 |
# File 'lib/anthropic/internal/util.rb', line 531 def initialize(src, &blk) @stream = case src in String StringIO.new(src) in Pathname @closing = true src.open(binmode: true) in Enumerator # Each retry or redirect reads the same body through a new adapter. Calling `next` on `src` itself would # resume where the previous adapter stopped; `to_enum` starts from the beginning. src.to_enum else src end @buf = String.new @blk = blk end |
Instance Method Details
#close ⇒ void
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.
This method returns an undefined value.
464 465 466 467 468 469 470 471 472 |
# File 'lib/anthropic/internal/util.rb', line 464 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.
461 |
# File 'lib/anthropic/internal/util.rb', line 461 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.
503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 |
# File 'lib/anthropic/internal/util.rb', line 503 def read(max_len = nil, out_string = nil) case @stream in nil out_string&.clear nil in IO | StringIO @stream.read(max_len, out_string) in Enumerator read = read_enum(max_len) case [out_string, read] in [String, String] out_string.replace(read) in [String, nil] out_string.clear nil in [nil, _] read end end .tap(&@blk) end |