[ANN] io-extra 0.1.0

D

Daniel Berger

Hi all,

I'm happy to announce the release of io-extra 0.1.0.

What is it?
===========
This package provides a few extra methods for the IO class:

IO.closefrom(low_fd)
- Closes all open file descriptors greater than or equal to 'low_fd'.

IO.fdwalk(low_fd)
- Iterates over each open file descriptor and yields back a File
object.

IO#directio?
- Returns true or false, depending on whether or not directio has been
set
for the filehandle.

IO#directio=
- Allows you to set directio for the filehandle (for those platforms
that support it).

Where is it?
============
It can be found on the RAA or on the project page at
http://ruby-miscutils.sf.net.

Eh? Is this really necessary?
==============================
Q) What is the difference between your implementation of IO.closefrom
and a
pure Ruby version that looks something like this?

def IO.closefrom(n)
0.upto n do |fd|
IO.for_fd(fd).close
end
end

The primary difference is that this walks all file descriptors, rather
than only open file descriptors. However, I should note that this only
applies if your platform supports the closefrom() function. In that
case,
the only advantage is speed.

Q) What is the difference between your implementation of IO.fdwalk and
a pure
Ruby version that looks something like this?

def IO.fdwalk(n)
ObjectSpace.each_object(File){ |f|
yield f if f.fileno >= n
}
end

The primary difference is that this only closes Ruby file objects, not
necessarily every filehandle opened by the Ruby process. Think
system(), for
example.

Enjoy!

Dan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

Forum statistics

Threads
474,262
Messages
2,571,057
Members
48,769
Latest member
Clifft

Latest Threads

Top