SEEK_SET | = | IO::SEEK_SET |
SEEK_END | = | IO::SEEK_END |
SEEK_CUR | = | IO::SEEK_CUR |
Rio Constructor
For purposes of discussion, we divide Rios into two catagories, those that have a path and those that don’t.
To create a Rio that has a path the arguments to rio may be:
rio('adir/afile')
rio('file:///atopleveldir/adir/afile')
rio(URI('adir/afile'))
rio('adir','afile')
rio(%w/adir afile/)
another_rio = rio('adir/afile') rio(another_rio)
rio(Pathname.new('apath'))
another_rio = rio('dir1/dir2') auri = URI('dir4/dir5) rio(another_rio,'dir3',auri,'dir6/dir7')
To create a Rio that refers to a web page the arguments to rio may be:
rio('http://ruby-doc.org/index.html')
rio(URI('http://ruby-doc.org/index.html'))
rio('http://www.ruby-doc.org/','core','classes/Object.html')
To create a Rio that refers to a file on a FTP server the arguments to rio may be:
rio('ftp://user:password@ftp.example.com/afile.tar.gz')
rio(URI('ftp://ftp.example.com/afile.tar.gz'))
rio('ftp://ftp.gnu.org/pub/gnu','emacs','windows','README')
To create a Rio without a path, the first argument to rio is usually a single character.
rio(?-) (mnemonic: ’-’ is used by some Unix programs to specify stdin or stdout in place of a file)
Just as a Rio that refers to a file, does not know whether that file will be opened for reading or writing until an I/O operation is specified, a stdio: Rio does not know whether it will connect to stdin or stdout until an I/O operation is specified.
rio(?=) (mnemonic: ’-’ refers to fileno 1, so ’=’ refers to fileno 2)
an_io = ::File.new('afile') rio(an_io)
rio(?#,fd) (mnemonic: a file descriptor is a number ’#’)
an_io = ::File.new('afile') fnum = an_io.fileno rio(?#,fnum)
rio(?") (mnemonic: ’"’ surrounds strings)
rio(?")
astring = "" rio(?",astring)
rio(??) (mnemonic: ’?’ you don’t know its name)
rio(??) rio(??,basename='rio',tmpdir=Dir::tmpdir)
To create a temporary object that will become a file or a directory, depending on how you use it:
rio(??) rio(??,basename='rio',tmpdir=Dir::tmpdir)
To force it to become a file
rio(??).file
or just write to it.
To force it to become a directory:
rio(??).dir
or
rio(??).mkdir
or
rio(??).chdir
rio('tcp:',hostname,port)
or
rio('tcp://hostname:port')
rio(?-,cmd) (mnemonic: ’-’ is used by some Unix programs to specify stdin or stdout in place of a file)
or
rio(?`,cmd) (mnemonic: ’`’ (backtick) runs an external program in ruby)
This is Rio’s interface to IO#popen
Copyright © 2005 Christopher Kleckner. All rights reserved.