Class: Modal::ModalReadStream
- Inherits:
-
Object
- Object
- Modal::ModalReadStream
- Defined in:
- lib/modal/streams.rb
Instance Method Summary collapse
- #close ⇒ Object
- #each(&block) ⇒ Object
-
#initialize(source_iterable) ⇒ ModalReadStream
constructor
A new instance of ModalReadStream.
- #read ⇒ Object
- #read_bytes ⇒ Object
- #read_text ⇒ Object
Constructor Details
#initialize(source_iterable) ⇒ ModalReadStream
Returns a new instance of ModalReadStream.
5 6 7 |
# File 'lib/modal/streams.rb', line 5 def initialize(source_iterable) @source_iterable = source_iterable end |
Instance Method Details
#close ⇒ Object
33 34 35 |
# File 'lib/modal/streams.rb', line 33 def close @source_iterable.close if @source_iterable.respond_to?(:close) end |
#each(&block) ⇒ Object
29 30 31 |
# File 'lib/modal/streams.rb', line 29 def each(&block) @source_iterable.each(&block) end |
#read ⇒ Object
9 10 11 |
# File 'lib/modal/streams.rb', line 9 def read read_text end |
#read_bytes ⇒ Object
21 22 23 24 25 26 27 |
# File 'lib/modal/streams.rb', line 21 def read_bytes chunks = [] @source_iterable.each do |bytes| chunks << bytes.dup end chunks.join("").bytes.pack("C*") end |
#read_text ⇒ Object
13 14 15 16 17 18 19 |
# File 'lib/modal/streams.rb', line 13 def read_text chunks = [] @source_iterable.each do |bytes| chunks << bytes.dup.force_encoding("UTF-8") end chunks.join("") end |