Class: FPM::Fry::BlockEnumerator Private
- Inherits:
-
Struct
- Object
- Struct
- FPM::Fry::BlockEnumerator
- 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
-
#blocksize ⇒ Object
Returns the value of attribute blocksize.
-
#io ⇒ Object
Returns the value of attribute io.
Instance Method Summary collapse
-
#call ⇒ String
private
Chunk or empty string at EOF.
-
#each {|chunk| ... } ⇒ Enumerator
private
Unless called with a block.
-
#initialize(io, blocksize = 128) ⇒ BlockEnumerator
constructor
private
A new instance of BlockEnumerator.
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.
10 11 12 |
# File 'lib/fpm/fry/block_enumerator.rb', line 10 def initialize(io, blocksize = 128) super end |
Instance Attribute Details
#blocksize ⇒ Object
Returns the value of attribute blocksize
5 6 7 |
# File 'lib/fpm/fry/block_enumerator.rb', line 5 def blocksize @blocksize end |
#io ⇒ Object
Returns the value of attribute io
5 6 7 |
# File 'lib/fpm/fry/block_enumerator.rb', line 5 def io @io end |
Instance Method Details
#call ⇒ String
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.
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.
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 |