undocumented
# File lib/rio/if/fileordir.rb, line 55 55: def open(m,*args,&block) target.open(m,*args,&block); self end
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 240 240: def pos() target.pos end
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 269 269: def pos=(integer) target.pos = integer end
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
Reads the next entry from _dir_ and returns it as a Rio. Returns
+nil+ at the end of the stream.
d = rio("testdir")
d.read #=> rio(".")
d.read #=> rio("..")
d.read #=> rio("config.h")
# File lib/rio/if/fileordir.rb, line 154 154: def read(*args) target.read(*args)end
Calls File#readlink
Returns a Rio referencing the file referenced by the given link. Not available on all platforms.
# File lib/rio/if/fileordir.rb, line 95 95: def readlink(*args) target.readlink(*args) end
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
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 122 122: def rename(*args,&block) target.rename(*args,&block); self end
For Streams calls IO#reopen, otherwise closes and re-opens the Rio.
# File lib/rio/if/fileordir.rb, line 274 274: def reopen(mode=nil) target.reopen(mode); self end
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
Repositions _ario_ to the first entry.
d = rio("testdir")
d.read #=> rio(".")
d.rewind.read #=> rio(".")
# File lib/rio/if/fileordir.rb, line 180 180: def rewind(&block) target.rewind(&block); self end
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 212 212: def seek(*args) target.seek(*args); self end
Creates a symbolic link dest which points to the Rio’s #fspath. Raises a NotImplementedError exception on platforms that do not support symbolic links. dest may be a Rio, a String, or anything that will create an appropriate Rio when passed to Rio#new . If dest already exists and is a directory, creates a symbolic link in the dest directory, named with the name returned by #filename. If dest already exists and it is not a directory, raises Errno::EEXIST.
Returns the Rio (not the symlink).
#symlink differs from File#symlink when the Rio or the dest path has directory information. In this case #symlink creates a symlink that actually refers to the Rio’s location from the perspective of the link’s location.
For example: Given an existing file ‘adir/afile’ and a dest of ‘adir/alink‘
::File.symlink('adir/afile','adir/alink1') # creates 'adir/alink1 -> adir/afile'
::File.exist?('adir/alink1') # false
rio('adir/afile').symlink('adir/alink2') # creates 'adir/alink2 -> afile'
::File.exist?('adir/alink2') # true
To replace an existing symlink use the following Rio idiom
rio('afile').symlink( rio('link_name').delete ) # delete 'link_name' and recreate linked to 'afile'
Examples
rio('afile').symlink('alink') # create the symbolic link 'alink' which references 'afile'
rio('afile').symlink('adir/alink') # create a symlink 'adir/alink' -> '../afile'
rio('adir/afile').symlink('alink') # create a symlink 'alink' -> 'adir/afile'
rio('adir/afile').symlink('adir/alink') # create a symlink 'adir/alink' -> 'afile'
rio('adir/afile').symlink('adir/alink') # create a symlink 'adir/alink' -> 'afile'
rio('adir1/afile').symlink('adir2/alink') # create a symlink 'adir2/alink' -> '../adir1/afile'
rio('/tmp/afile').symlink('alink') # create a symlink 'adir/alink' -> '/tmp/afile'
# File lib/rio/if/fileordir.rb, line 88 88: def symlink(dest) target.symlink(dest); self end
See #pos
# File lib/rio/if/fileordir.rb, line 243 243: def tell() target.tell end
Copyright © 2005,2006,2007,2008,2009,2010 Christopher Kleckner. All rights reserved.