Class: FPM::Fry::BlockEnumerator
- Inherits:
-
Struct
- Object
- Struct
- FPM::Fry::BlockEnumerator
- Includes:
- Enumerable
- Defined in:
- lib/fpm/fry/block_enumerator.rb
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
Chunk or empty string at EOF.
-
#each {|chunk| ... } ⇒ Enumerator
Unless called with a block.
-
#initialize(_, blocksize = 128) ⇒ BlockEnumerator
constructor
A new instance of BlockEnumerator.
Constructor Details
#initialize(_, blocksize = 128) ⇒ BlockEnumerator
Returns a new instance of BlockEnumerator.
7 8 9 |
# File 'lib/fpm/fry/block_enumerator.rb', line 7 def initialize(_, blocksize = 128) super end |
Instance Attribute Details
#blocksize ⇒ Object
Returns the value of attribute blocksize
2 3 4 |
# File 'lib/fpm/fry/block_enumerator.rb', line 2 def blocksize @blocksize end |
#io ⇒ Object
Returns the value of attribute io
2 3 4 |
# File 'lib/fpm/fry/block_enumerator.rb', line 2 def io @io end |
Instance Method Details
#call ⇒ String
Returns chunk or empty string at EOF.
24 25 26 27 28 29 30 |
# File 'lib/fpm/fry/block_enumerator.rb', line 24 def call while x = io.read(blocksize) next if x == "" return x end return "" end |
#each {|chunk| ... } ⇒ Enumerator
Returns unless called with a block.
14 15 16 17 18 19 20 21 |
# File 'lib/fpm/fry/block_enumerator.rb', line 14 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 |