class FPM::Fry::BlockEnumerator

Helper class that reads an IO in chunks.

@api private

Public Class Methods

new(io, blocksize = 128) click to toggle source

@param [IO] io @param [Numeric] blocksize

Calls superclass method
# File lib/fpm/fry/block_enumerator.rb, line 10
def initialize(io, blocksize = 128)
  super
end

Public Instance Methods

call() click to toggle source

@return [String] chunk or empty string at EOF

# File lib/fpm/fry/block_enumerator.rb, line 27
 def call
   while x = io.read(blocksize)
     next if x == ""
     return x
   end
   return ""
end
each() { |chunk| ... } click to toggle source

@return [Enumerator] unless called with a block @yield [chunk] One chunk from the io @yieldparam chunk [String]

# File lib/fpm/fry/block_enumerator.rb, line 17
def each
  return to_enum unless block_given?
  # Reading bigger chunks is far more efficient than invoking #each on an IO.
  while chunk = io.read(blocksize)
    yield chunk
  end
  return nil
end