class Arroyo::Stream

Public Class Methods

new(source) click to toggle source
# File lib/arroyo/stream.rb, line 3
def initialize(source)
  @source = source
end

Public Instance Methods

copy_to(destination) click to toggle source

Public: Copy stream data to the given destination.

destination - a File, IO, String path, or IO-like object responding to write

Returns nothing.

# File lib/arroyo/stream.rb, line 33
def copy_to(destination)
  IO.copy_stream self, destination
end
each(*args) { |chunk| ... } click to toggle source

Public: Iterate over chunks of String data as they're read from the stream.

length - the maximum number of bytes to read in each iteration (optional; default is 16 KB)

Returns nothing.

# File lib/arroyo/stream.rb, line 22
def each(*args)
  while chunk = readpartial(*args)
    yield chunk
  end
end
readpartial(*args) click to toggle source

Public: Read at most `length` bytes from the stream, blocking only if it has no data immediately available. If the stream has any data available, this method does not block.

length - the maximum number of bytes to read (optional; default is 16 KB)

Returns String data from the stream or nil if EOF has been reached.

# File lib/arroyo/stream.rb, line 13
def readpartial(*args)
  @source.readpartial(*args)
end