Class: FPM::Fry::BlockEnumerator Private

Inherits:
Struct
  • Object
show all
Includes:
Enumerable
Defined in:
lib/fpm/fry/block_enumerator.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Helper class that reads an IO in chunks.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(io, blocksize = 128) ⇒ BlockEnumerator

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of BlockEnumerator.

Parameters:

  • io (IO)
  • blocksize (Numeric) (defaults to: 128)


10
11
12
# File 'lib/fpm/fry/block_enumerator.rb', line 10

def initialize(io, blocksize = 128)
  super
end

Instance Attribute Details

#blocksizeObject

Returns the value of attribute blocksize

Returns:

  • (Object)

    the current value of blocksize



5
6
7
# File 'lib/fpm/fry/block_enumerator.rb', line 5

def blocksize
  @blocksize
end

#ioObject

Returns the value of attribute io

Returns:

  • (Object)

    the current value of io



5
6
7
# File 'lib/fpm/fry/block_enumerator.rb', line 5

def io
  @io
end

Instance Method Details

#callString

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns chunk or empty string at EOF.

Returns:

  • (String)

    chunk or empty string at EOF



27
28
29
30
31
32
33
# 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| ... } ⇒ Enumerator

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns unless called with a block.

Yields:

  • (chunk)

    One chunk from the io

Yield Parameters:

  • chunk (String)

Returns:

  • (Enumerator)

    unless called with a block



17
18
19
20
21
22
23
24
# 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