module RIO::IF::FileOrDir

Public Instance Methods

open(m,*args,&block) click to toggle source

undocumented

# File lib/rio/if/fileordir.rb, line 29
def open(m,*args,&block) target.open(m,*args,&block); self end
pos() click to toggle source

For directories calls Dir#pos, otherwise calls IO#pos

For streams calls IO#pos

ario.pos     => integer
ario.tell    => integer

Returns the current offset (in bytes) of ario.

f = rio("testfile")
f.pos    #=> 0
f.gets   #=> "This is line one\n"
f.pos    #=> 17

For directories calls Dir#pos

ario.pos => integer
ario.tell => integer

Returns the current position in dir. See also #seek.

d = rio("testdir")
d.pos   #=> 0
d.read  #=> rio(".")
d.pos   #=> 12
# File lib/rio/if/fileordir.rb, line 214
def pos() target.pos end
pos=(integer) click to toggle source

For directories calls Dir#pos=, otherwise calls IO#pos=

For streams calls IO#pos=

ario.pos = integer    => 0

Seeks to the given position (in bytes) in ario.

f = rio("testfile")
f.pos = 17
f.gets   #=> "This is line two\n"

For directories calls Dir#pos=

ario.pos = integer     => integer

Synonym for #seek, but returns the position parameter.

d = rio("testdir")       #=> d
d.read                   #=> rio(".")
i = d.pos                #=> 12
d.read                   #=> rio("..")
d.pos = i                #=> 12
d.read                   #=> rio("..")
# File lib/rio/if/fileordir.rb, line 243
def pos=(integer) target.pos = integer end
read(*args) click to toggle source

For directories calls Dir#read, otherwise calls IO#read

For streams calls IO#read

ario.read([integer [, buffer]])    => string, buffer, or nil

Reads at most integer bytes from the I/O stream, or to the end of file if integer is omitted or is nil. If the optional buffer argument is present, it must reference a String, which will receive the data. Returns nil if called at end of file.

f = rio("testfile")
f.read(16)   #=> "This is line one"

rio("testfile").read(16) #=> "This is line one"

For directories calls Dir#read

dir.read => ario or nil
# File lib/rio/if/fileordir.rb, line 128
def read(*args) target.read(*args)end
rename(*args,&block) click to toggle source

If called with an argument calls FileUtils#rename. If called without an argument puts the Rio in “rename mode”.

Proxy for FileUtils#rename

ario = rio('afile.cpp')
ario.rename('afile.cxx') # renamed the file, but ario still references
                         # the old path
Rename Mode

In rename mode, changes to a Rio's path using #dirname=, #filename=, #basename=, and #extname= also cause the object on the filesystem to be renamed.

Change the extension of all'.cpp' files in 'adir' to '.cxx'

rio('adir').rename.files('*.cpp') do |file|
  file.ext = '.cxx' # 'file' references the new path and the actual file is renamed
end

Recursively change all '.tar.gz' files to '.tgz' files

rio('adir').rename.all.files('*.tar.gz') do |gzfile|
  gzfile.ext('.tar.gz').ext = '.tgz'
end

See #dirname=, #filename=, #basename=, and #extname=

# File lib/rio/if/fileordir.rb, line 96
def rename(*args,&block) target.rename(*args,&block); self end
rename!(*args,&block) click to toggle source

Behaves like #rename, but also changes the calling Rio to refer to the renamed path

# File lib/rio/if/fileordir.rb, line 101
def rename!(*args,&block) target.rename!(*args,&block); self end
reopen(mode=nil) click to toggle source

For Streams calls IO#reopen, otherwise closes and re-opens the Rio.

# File lib/rio/if/fileordir.rb, line 248
def reopen(mode=nil) target.reopen(mode); self end
rewind(&block) click to toggle source

For directories proxies Dir#rewind, otherwise proxies IO#rewind

Proxy for IO#rewind

ario.rewind   => ario

Positions ario to the beginning of input, resetting lineno to zero.

Returns the Rio

f = rio("testfile")
f.readline   #=> "This is line one\n"
f.rewind     #=> f
f.lineno     #=> 0
f.readline   #=> "This is line one\n"

f.rewind.readline #=> "This is line one\n"

Proxy for Dir#rewind

ario.rewind => ario
# File lib/rio/if/fileordir.rb, line 154
def rewind(&block) target.rewind(&block); self end
seek(*args) click to toggle source

For directories calls Dir#seek, otherwise calls IO#seek

For streams calls IO#seek

ario.seek(amount, whence=SEEK_SET) -> ario

Seeks to a given offset amount in the stream according to the value of whence:

IO::SEEK_CUR  | Seeks to 'amount' plus current position
--------------+----------------------------------------------------
IO::SEEK_END  | Seeks to 'amount' plus end of stream (you probably
              | want a negative value for 'amount')
--------------+----------------------------------------------------
IO::SEEK_SET  | Seeks to the absolute location given by 'amount'

Example:

f = rio("testfile")
f.seek(-28, IO::SEEK_END).readline                  #=> "happily ever after. The End\n"

For directories calls Dir#seek

ario.seek( integer ) => ario

Seeks to a particular location in ario. integer must be a value returned by #tell.

d = rio("testdir")       #=> #<RIO::Rio:0x401b3c40>
d.read                   #=> rio(".")
i = d.tell               #=> 12
d.read                   #=> rio("..")
d.seek(i)                #=> #<RIO::Rio:0x401b3c40>
d.read                   #=> rio("..")
# File lib/rio/if/fileordir.rb, line 186
def seek(*args) target.seek(*args); self end
tell() click to toggle source

See #pos

# File lib/rio/if/fileordir.rb, line 217
def tell() target.tell end