# Rio 0.3.7

**URL:** <https://www.ruby-forum.com/t/rio-0-3-7/89673>\
**Category:** Ruby\
**Created:** [January 5, 2006, 5:19am UTC](https://www.ruby-forum.com/t/rio-0-3-7/89673 "2006-01-05T05:19:17Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![rio4ruby](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/82dd89/32.png) [@rio4ruby](https://www.ruby-forum.com/u/rio4ruby)\
**Post date:** [January 5, 2006, 5:19am UTC](https://www.ruby-forum.com/t/rio-0-3-7/89673/1 "2006-01-05T05:19:17Z")

</div>

Announcing Rio 0.3.7

== Overview

Rio is a Ruby I/O convenience class wrapping much of the functionality  
of IO, File and Dir. Rio also uses FileUtils, Tempfile, StringIO,  
OpenURI, Zlib, and CSV to provide similar functionality using a simple  
consistent interface. In addition to forwarding the interfaces  
provided by IO, File, and Dir to an appropriate object, Rio provides a  
“grande” interface that allows many common application-level I/O and  
file-system tasks to be expressed succinctly.

== New

Support for Pipe operator

# Pipe multiple commands

rio(‘afile’) | rio(?-,‘acmd’) | ‘another\_cmd’ | ?-

# run the same series of commands, with different input and/or output

cmdpipe = rio(?-,‘acmd’) | rio(?-,‘another\_cmd’)  
rio(‘infile1’) | cmdpipe | rio(‘outfile1’)  
rio(‘infile2’) | cmdpipe | rio(‘outfile2’)

cmdpipe2 = rio(?|,‘cmd1’,‘cmd2’,rio(‘outfile’)) # a cmdpipe Rio  
rio(‘infile1’) | cmdpipe2 # run with input coming from a file  
rio(?-) | cmdpipe2 # same commands with input from stdin

Improved support for MS Windows paths containing drives and UNC paths.  
rio(‘D:/adir/afile’)  
rio(‘//ahost/adir/afile’)

== SYNOPSIS

For the following assume:  
astring = “”  
anarray = []

Copy or append a file to a string  
rio(‘afile’) \> astring # copy  
rio(‘afile’) \>\> astring # append

Copy or append a string to a file  
rio(‘afile’) \< astring # copy  
rio(‘afile’) \<\< astring # append

Copy or append the lines of a file to an array  
rio(‘afile’) \> anarray  
rio(‘afile’) \>\> anarray

Copy or append a file to another file  
rio(‘afile’) \> rio(‘another\_file’)  
rio(‘afile’) \>\> rio(‘another\_file’)

Copy a file to a directory  
rio(‘adir’) \<\< rio(‘afile’)

Copy a directory structure to another directory  
rio(‘adir’) \>\> rio(‘another\_directory’)

Copy a web-page to a file  
rio(‘[http://rubydoc.org/](http://rubydoc.org/)’) \> rio(‘afile’)

Ways to get the chomped lines of a file into an array  
anarray = rio(‘afile’).chomp[] # subscript operator  
rio(‘afile’).chomp \> anarray # copy-to operator  
anarray = rio(‘afile’).chomp.to\_a # to\_a  
anarray = rio(‘afile’).chomp.readlines # IO#readlines

Copy a gzipped file un-gzipping it  
rio(‘afile.gz’).gzip \> rio(‘afile’)

Copy a plain file, gzipping it  
rio(‘afile.gz’).gzip \< rio(‘afile’)

Copy a file from a ftp server into a local file un-gzipping it  
rio(‘ftp://host/afile.gz’).gzip \> rio(‘afile’)

Iterate over the entries in a directory  
rio(‘adir’).entries { |entrio| … }

Iterate over only the files in a directory  
rio(‘adir’).files { |entrio| … }

Iterate over only the .rb files in a directory  
rio(‘adir’).files(‘\*.rb’) { |entrio| … }

Iterate over .rb files but not symlinks to .rb files  
rio(‘adir’).files(‘\*.rb’).skip(:symlink?) { |entrio| … }

Iterate over only the _dot_ files in a directory  
rio(‘adir’).files(/^./) { |entrio| … }

Iterate over the files in a directory and its subdirectories, skipping  
‘.svn’ and ‘CVS’ directories

rio(‘adir’).norecurse(/^.svn$/,‘CVS’).files { |entrio| … }

Create an array of the .rb entries in a directory  
anarray = rio(‘adir’)[‘\*.rb’]

Create an array of the .rb entries in a directory and its  
subdirectories.  
anarray = rio(‘adir’).all[‘\*.rb’]

Iterate over the .rb files in a directory and its subdirectories  
rio(‘adir’).all.files(‘\*.rb’) { |entrio| … }

Iterate over the non-empty, non-comment chomped lines of a file  
rio(‘afile’).chomp.skip.lines(:empty?,/^\s\*#/) { |line| … }

Copy the output of th ps command into an array, skipping the header  
line and the ps command entry  
rio(?-,‘ps -a’).skip.lines(0,/ps$/) \> anarray

Prompt for input and return what was typed  
ans = rio(?-).print("Type Something: ").chomp.gets

Change the extension of all .htm files in a directory and its  
subdirectories to .html  
rio(‘adir’).rename.all.files(‘\*.htm’) do |htmfile|  
htmfile.extname = ‘.html’  
end

Create a symbolic link ‘asymlink’ in ‘adir’ which refers to  
‘adir/afile’  
rio(‘adir/afile’).symlink(‘adir/asymlink’)

Copy a CSV file, changing the separator to a semicolon  
rio(‘comma.csv’).csv \> rio(‘semicolon.csv’).csv(‘;’)

Iterate through a CSVfile with each line parsed into an array  
rio(‘afile.csv’).csv { |array\_of\_fields| …}

Create a tab separated file of accounts in a UNIX passwd file,  
listing only the username, uid, and realname fields  
rio(‘/etc/passwd’).csv(‘:’).columns(0,2,4) \> rio(‘rpt’).csv(“\t”)

== Contact

Project:: [http://rubyforge.org/projects/rio/](http://rubyforge.org/projects/rio/)  
Documentation:: [http://rio.rubyforge.org/](http://rio.rubyforge.org/)  
Bugs:: [http://rubyforge.org/tracker/?group\_id=821](http://rubyforge.org/tracker/?group_id=821)  
Email:: removed\_email\_address@domain.invalid

== Copyright  
Copyright (c) 2005,2006 Christopher Kleckner. All rights reserved

== License  
Rio is released under the GNU General Public License  
([The GNU General Public License v3.0 - GNU Project - Free Software Foundation](http://www.gnu.org/licenses/gpl.html))

-Christopher Kleckner

---

<div class="post-metadata">

**Author:** ![rio4ruby](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/82dd89/32.png) [@rio4ruby](https://www.ruby-forum.com/u/rio4ruby)\
**Post date:** [January 5, 2006, 11:59am UTC](https://www.ruby-forum.com/t/rio-0-3-7/89673/2 "2006-01-05T11:59:53Z")

</div>

On Thu, 5 Jan 2006, rio4ruby wrote:

> Announcing Rio 0.3.7

Great! That solved my problem with rio#mkdir with 0.3.4 under linux!  
Thanks everybody for the really intensive help and the massive number  
(1)  
of reactions to my mails (5) about that problem!

---

<div class="post-metadata">

**Author:** ![rio4ruby](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/82dd89/32.png) [@rio4ruby](https://www.ruby-forum.com/u/rio4ruby)\
**Post date:** [January 5, 2006, 5:40pm UTC](https://www.ruby-forum.com/t/rio-0-3-7/89673/3 "2006-01-05T17:40:45Z")

</div>

rio4ruby wrote:

> file-system tasks to be expressed succinctly.  
> Bravo !

… Because :  
… It is very useful.  
… It is well documented.

I just had a quick look at the doc, I’m a newbie and I didn’t understand  
everything, things will be clearer when I’ll use Rio.

Thanks !

> == Contact

---

<div class="post-metadata">

**Author:** ![rio4ruby](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/82dd89/32.png) [@rio4ruby](https://www.ruby-forum.com/u/rio4ruby)\
**Post date:** [January 5, 2006, 5:44pm UTC](https://www.ruby-forum.com/t/rio-0-3-7/89673/4 "2006-01-05T17:44:31Z")

</div>

Very nice!

Another step that Ruby makes to dominate the world!

–

> here are more things in heaven and earth,  
> horatio, than are dreamt of in your philosophy.

–  
Email.it, the professional e-mail, gratis per te: [http://www.email.it/f](http://www.email.it/f)

Sponsor:  
Personalizza il tuo cellulare con le immagini più divertenti o con le foto  
di chi ami  
\*  
Clicca qui: [http://adv.email.it/cgi-bin/foclick.cgi?mid=3117&d=5-1](http://adv.email.it/cgi-bin/foclick.cgi?mid=3117&d=5-1)

---

<div class="post-metadata">

**Author:** ![rio4ruby](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/82dd89/32.png) [@rio4ruby](https://www.ruby-forum.com/u/rio4ruby)\
**Post date:** [January 10, 2006, 12:38am UTC](https://www.ruby-forum.com/t/rio-0-3-7/89673/5 "2006-01-10T00:38:19Z")

</div>

Duane J. wrote:

> > Copy a gzipped file un-gzipping it  
> > rio(‘afile.gz’).gzip \> rio(‘afile’)
> 
> Why does ‘gzip’ unzip? How would one zip something up?

Rio#gzip puts a Rio in gzip mode, so the referenced  
file will be read from and written to properly. We could  
rewrite the example:

a\_rio\_referencing\_a\_gzipped\_file = rio('afile.gz).gzip  
a\_rio\_referencing\_a\_file = rio(‘afile’)  
a\_rio\_referencing\_a\_gzipped\_file \> a\_rio\_referencing\_a\_file

> How would one zip something up?

Turn the arrow around:  
rio(‘afile.gz’).gzip \< rio(‘afile’)

> Curious… why does +all+ take square brackets when +files+ uses  
> parens? Seems inconsistent upon first viewing.

Both +files+ and +all+ are configuration methods.

The usage:

anarray = rio(‘adir’).all[’\*.rb’]

is syntactic sugar for

anarray = rio(‘adir’).all.entries(’\*.rb’).to\_a

The abbreviated usage works because:

1. Rio#entries is the default selection method when iterating  
over directories.
2. The subscript operator passes its arguments to the most  
recently called selection method (in this case +entries+,  
even though it was never _explicitly_ called) before it  
calls +to\_a+.
3. Rio#all returns the Rio which called it. (All configuration  
methods do this, to support the readable shortened syntax)

Since Rio#files is also a configuration method, it can be used  
similarly:

rio(‘adir’).files(’_.rb’) { |f| … } # iterate over .rb files  
rio(‘adir’).files[’_.rb’] # returns an array of .rb files  
rio(‘adir’).files(’\*.rb’) \> ‘bdir’ # copies .rb files to ‘bdir’

Hope this helps.  
-Christopher

---

<div class="post-metadata">

**Author:** ![rio4ruby](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/82dd89/32.png) [@rio4ruby](https://www.ruby-forum.com/u/rio4ruby)\
**Post date:** [January 5, 2006, 5:44pm UTC](https://www.ruby-forum.com/t/rio-0-3-7/89673/6 "2006-01-05T17:44:41Z")

</div>

Hi Christopher! This is my first time looking at Rio, and I’m very  
impressed! I have a few interface questions for you–things that  
jumped out at me on my initial viewing of the examples. Again, this  
is coming from a white page here, so take it either as “how a new guy  
sees the library” or with a grain of salt 🙂

On Jan 4, 2006, at 9:17 PM, rio4ruby wrote:

> Announcing Rio 0.3.7

\> Copy a gzipped file un-gzipping it \> rio('afile.gz').gzip \> rio('afile') \> Why does 'gzip' unzip? How would one zip something up? \> Iterate over .rb files but not symlinks to .rb files \> rio('adir').files('\*.rb').skip(:symlink?) { |entrio| ... } \> \> Iterate over only the \_dot\_ files in a directory \> rio('adir').files(/^\./) { |entrio| ... } \> \> Create an array of the .rb entries in a directory and its \> subdirectories. \> anarray = rio('adir').all['\*.rb'] \> Curious... why does +all+ take square brackets when +files+ uses parens? Seems inconsistent upon first viewing.

Super work! I look forward to using this in the future.

Duane J.  
(canadaduane)  
[http://blog.inquirylabs.com/](http://blog.inquirylabs.com/)

---

<div class="post-metadata">

**Author:** ![rio4ruby](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/82dd89/32.png) [@rio4ruby](https://www.ruby-forum.com/u/rio4ruby)\
**Post date:** [January 12, 2006, 7:59pm UTC](https://www.ruby-forum.com/t/rio-0-3-7/89673/7 "2006-01-12T19:59:37Z")

</div>

Thanks Christopher,

I just started using Rio and it’s very handy.

I’m trying to get Rio to work with file names that have a space in  
them. E.g “Foo B.”.

## Works

rio(‘foobar’) \<\< “testing” # no space in file name

## Does not work

rio(“"foo bar"”) \<\< “testing”  
rio(‘foo\ bar’) \<\< “testing”  
rio(“foo bar”) \<\< “testing”  
rio(‘foo\sbar’) \<\< “testing”  
rio(“foo\sbar”) \<\< “testing”

I’m running on WinXP and installed Ruby with the one click installer.  
I installed Rio with

> gem install rio  
> but that got me 0.3.4

I’ve not been able to figure out how to specify a particular version  
for gem to use.

> gem install rio --source [http://rubyforge.org/frs/download.php/7291/rio-0.3.7.gem](http://rubyforge.org/frs/download.php/7291/rio-0.3.7.gem)

> “c:\ruby\bin\ruby.exe” “c:\ruby\bin\gem” install rio --source [http://rubyforge.org/frs/download.php/7291/rio-0.3.7.gem](http://rubyforge.org/frs/download.php/7291/rio-0.3.7.gem)  
> Attempting local installation of ‘rio’  
> Local gem file not found: rio\*.gem  
> Attempting remote installation of ‘rio’  
> Updating Gem source index for:  
> [http://rubyforge.org/frs/download.php/7291/rio-0](http://rubyforge.org/frs/download.php/7291/rio-0).  
> 3.7.gem  
> ERROR: While executing gem … (ArgumentError)  
> parse error on line 0, col 11: `data.tar.gz’

did not work for me

Any help appeciated.

Thanks,  
Dale

---

<div class="post-metadata">

**Author:** ![rio4ruby](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/82dd89/32.png) [@rio4ruby](https://www.ruby-forum.com/u/rio4ruby)\
**Post date:** [January 10, 2006, 3:15am UTC](https://www.ruby-forum.com/t/rio-0-3-7/89673/8 "2006-01-10T03:15:01Z")

</div>

On Jan 9, 2006, at 4:38 PM, rio4ruby wrote:

> a\_rio\_referencing\_a\_gzipped\_file = rio('afile.gz).gzip
> 
> The abbreviated usage works because:  
> similarly:
> 
> rio(‘adir’).files(‘_.rb’) { |f| … } # iterate over .rb files  
> rio(‘adir’).files['_.rb’] # returns an array of .rb  
> files  
> rio(‘adir’).files(‘\*.rb’) \> ‘bdir’ # copies .rb files to ‘bdir’
> 
> Hope this helps.  
> -Christopher

Fantastic! Thanks again. I’m loving Rio more and more 🙂

Duane J.  
(canadaduane)  
[http://blog.inquirylabs.com/](http://blog.inquirylabs.com/)
