Class: Magritte::BlockStream
- Inherits:
-
Object
- Object
- Magritte::BlockStream
- Extended by:
- Forwardable
- Defined in:
- lib/magritte/iostreams.rb
Constant Summary collapse
- READ_BLOCK_SIZE =
512
Instance Attribute Summary collapse
-
#io ⇒ Object
readonly
Returns the value of attribute io.
Instance Method Summary collapse
-
#initialize(io) ⇒ BlockStream
constructor
A new instance of BlockStream.
- #read ⇒ Object
- #write(data) ⇒ Object
Constructor Details
#initialize(io) ⇒ BlockStream
Returns a new instance of BlockStream.
12 13 14 |
# File 'lib/magritte/iostreams.rb', line 12 def initialize(io) @io = io end |
Instance Attribute Details
#io ⇒ Object (readonly)
Returns the value of attribute io.
9 10 11 |
# File 'lib/magritte/iostreams.rb', line 9 def io @io end |
Instance Method Details
#read ⇒ Object
27 28 29 30 31 32 33 34 35 36 |
# File 'lib/magritte/iostreams.rb', line 27 def read begin data = @io.read_nonblock(READ_BLOCK_SIZE) unless @io.closed? rescue EOFError @io.close rescue Errno::EAGAIN end data || "" end |
#write(data) ⇒ Object
16 17 18 19 20 21 22 23 24 25 |
# File 'lib/magritte/iostreams.rb', line 16 def write(data) return 0 if data.empty? return 0 if @io.closed? begin @io.write_nonblock(data) rescue Errno::EAGAIN return 0 end end |