Class: Microsandbox::FsReadStream
- Inherits:
-
Object
- Object
- Microsandbox::FsReadStream
- Includes:
- Enumerable
- Defined in:
- lib/microsandbox/fs.rb
Overview
A streaming reader over a guest file, from Microsandbox::FS#read_stream. Iterate it (it is Enumerable) to consume byte chunks (ASCII-8BIT) as they arrive, or call #read to drain it into one String.
Instance Method Summary collapse
-
#each {|chunk| ... } ⇒ self, Enumerator
Yield each chunk of bytes until the stream ends.
-
#initialize(native) ⇒ FsReadStream
constructor
A new instance of FsReadStream.
-
#read ⇒ String
Drain the stream into a single byte String.
Constructor Details
#initialize(native) ⇒ FsReadStream
Returns a new instance of FsReadStream.
205 206 207 |
# File 'lib/microsandbox/fs.rb', line 205 def initialize(native) @native = native end |
Instance Method Details
#each {|chunk| ... } ⇒ self, Enumerator
Yield each chunk of bytes until the stream ends. Returns an Enumerator when called without a block.
213 214 215 216 217 218 219 220 |
# File 'lib/microsandbox/fs.rb', line 213 def each return enum_for(:each) unless block_given? while (chunk = @native.recv) yield chunk end self end |
#read ⇒ String
Drain the stream into a single byte String.
224 225 226 227 228 |
# File 'lib/microsandbox/fs.rb', line 224 def read buffer = +"".b each { |chunk| buffer << chunk } buffer end |