class Tofu::ChunkedStream
Public Class Methods
new(stream)
click to toggle source
# File lib/tofu.rb, line 591 def initialize(stream) @data = nil @cursor = 0 @stream = stream end
Public Instance Methods
close()
click to toggle source
# File lib/tofu.rb, line 603 def close @stream.close end
next_chunk()
click to toggle source
# File lib/tofu.rb, line 597 def next_chunk @stream.pop rescue raise EOFError end
readpartial(size, buf='')
click to toggle source
# File lib/tofu.rb, line 607 def readpartial(size, buf='') buf.clear unless @data @cursor = 0 @data = next_chunk @data.force_encoding("ascii-8bit") end if @data.bytesize <= size buf << @data @data = nil else slice = @data.byteslice(@cursor, size) @cursor += slice.bytesize buf << slice if @data.bytesize <= @cursor @data = nil end end buf end