Encapsulates I/O access over a file handle (fid).
NOTE: this class is NOT thread-safe.
Methods
Attributes
[R] | fid | |
[R] | stat | |
[R] | eof | |
[RW] | pos |
Class Public methods
Instance Public methods
Alias for write
Closes this stream.
Returns true if this stream is closed.
Reads some data from this stream at the current position.
- partial
- When false, the entire content of this stream is read and returned.
When true, the maximum amount of content that can fit inside a single 9P2000 message is read and returned.
If this stream corresponds to a directory, then an Array of Stat (one for each file in the directory) will be returned.
# File lib/rumai/ixp/transport.rb, line 244 def read partial = false raise 'cannot read from a closed stream' if @closed content = '' begin req = Tread.new( :fid => @fid, :offset => @pos, :count => @msize ) rsp = @agent.talk(req) content << rsp.data count = rsp.count @pos += count end until @eof = count.zero? or partial # the content of a directory is a sequence # of Stat for all files in that directory if @stat.directory? buffer = StringIO.new(content) content = [] until buffer.eof? content << Stat.from_9p(buffer) end end content end
Rewinds the stream to the beginning.
Writes the given content at the current position in this stream.
This method is also aliased as
<<
# File lib/rumai/ixp/transport.rb, line 278 def write content raise 'closed streams cannot be written to' if @closed raise 'directories cannot be written to' if @stat.directory? data = content.to_s limit = data.length + @pos while @pos < limit chunk = data[@pos, @msize] req = Twrite.new( :fid => @fid, :offset => @pos, :count => chunk.length, :data => chunk ) rsp = @agent.talk(req) @pos += rsp.count end end