Class: IPFS::IO::ReadFromWriterIO
- Inherits:
-
Object
- Object
- IPFS::IO::ReadFromWriterIO
- Defined in:
- lib/ipfs-api/io.rb
Overview
:nodoc:
Instance Method Summary collapse
-
#initialize(&block) ⇒ ReadFromWriterIO
constructor
A new instance of ReadFromWriterIO.
- #read(length = nil, outbuf = '') ⇒ Object
Constructor Details
#initialize(&block) ⇒ ReadFromWriterIO
Returns a new instance of ReadFromWriterIO.
8 9 10 11 12 |
# File 'lib/ipfs-api/io.rb', line 8 def initialize &block @block = block @stream = StringIO.new fetch_data end |
Instance Method Details
#read(length = nil, outbuf = '') ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/ipfs-api/io.rb', line 14 def read length = nil, outbuf = '' return nil if @stream.size == 0 outbuf.slice!(length..-1) if !length.nil? q = 0 while @stream.size > 0 s = @stream.size - @p s = [length - q, s].min if !length.nil? outbuf[q, s] = @stream.string[@p, s] @p += s q += s break if q == length fetch_data if @stream.size == @p end outbuf end |