Class: RStyx::Client::Directory
- Inherits:
-
Object
- Object
- RStyx::Client::Directory
- Includes:
- Enumerable
- Defined in:
- lib/rstyx/client.rb
Overview
Styx directory. This obtains the entries inside a directory, and works by delegating to File.
Instance Method Summary collapse
- #close ⇒ Object
-
#each ⇒ Object
Call the block once for each entry in the directory, passing the filename of each entry as a parameter to the block.
- #fid ⇒ Object
-
#initialize(fp) ⇒ Directory
constructor
A new instance of Directory.
- #qid ⇒ Object
-
#read ⇒ Object
Read the next directory entry from the dir and return the file name as a string.
Constructor Details
#initialize(fp) ⇒ Directory
Returns a new instance of Directory.
974 975 976 977 978 979 980 |
# File 'lib/rstyx/client.rb', line 974 def initialize(fp) @io = fp # directory entry buffer @read_direntries = [] # byte buffer @data = "" end |
Instance Method Details
#close ⇒ Object
982 983 984 |
# File 'lib/rstyx/client.rb', line 982 def close @io.close end |
#each ⇒ Object
Call the block once for each entry in the directory, passing the filename of each entry as a parameter to the block.
1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 |
# File 'lib/rstyx/client.rb', line 1036 def each if !block_given? raise LocalJumpError.new("no block given") end self.rewind until (de = read).nil? yield de end end |
#fid ⇒ Object
986 987 988 |
# File 'lib/rstyx/client.rb', line 986 def fid @io.fid end |
#qid ⇒ Object
990 991 992 |
# File 'lib/rstyx/client.rb', line 990 def qid @io.qid end |
#read ⇒ Object
Read the next directory entry from the dir and return the file name as a string. Returns nil at the end of stream.
998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 |
# File 'lib/rstyx/client.rb', line 998 def read # if there are directory entries left over from the previous # read that have not yet been returned, return them. if @read_direntries.length != 0 return(@read_direntries.shift.name) end # read iounit bytes from the directory--this must be unbuffered d = @io.sysread if d.nil? return(nil) end @data << d if (@data.empty?) return(nil) end # decode the directory entries in the iounit loop do delen = @data.unpack("v")[0] if delen.nil? || delen + 1 > @data.length break end edirent = @data[0..(delen + 1)] @data = @data[(delen + 2)..-1] @read_direntries << Message::Stat.from_bytes(edirent) end de = @read_direntries.shift if (de.nil?) return(nil) end return(de.name) end |