The io-extra library provides a few extra IO methods that you may find
handy. They are IO.closefrom, IO.fdwalk, IO.pread, IO.pread_ptr, IO.pwrite,
IO.writev, IO#directio? and IO#directio=.
This library is not supported on MS Windows.
Support for OS X is limited. See the documentation for details.
gem install io-
puts "=" * 40
IO.writev(fh.fileno, %w[a b c])
You might be wondering what the difference is between my implementation of
IO.closefrom and a pure Ruby version that looks something like this:
0.upto(n) do |fd|
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.
You might also be wondering what the difference is between my implementation
of IO.fdwalk and a pure Ruby version that looks something like this:
yield f if f.fileno >= n
The primary difference is that this only closes Ruby file objects, not
necessarily every file handle opened by the Ruby process. For example, handles
opened via system() calls.
Note to OS X Users
The OS X platform does not support closefrom(), fdwalk() or directio(). The
hand-crafted IO.closefrom function will not work because the getrlimit()
function on OS X does not work. Patches welcome.
For further documentation, see the io_extra.txt file or the inline
documentation that was generated by RDoc (if you did a gem install).
The IO.writev tests fail on Solaris. We are not sure why yet.
Please file any bug reports on the project page at
* I may add the File::O_DIRECT open constant on platforms that support it.
* Switch from C extension to FFI.
Eric Wong for some great work on Linux compatibility and other fixes, as
well as the code for the IO.writev method.
(C) 2003-2010 Daniel J. Berger
All Rights Reserved
This package is provided "as is" and without any express or
implied warranties, including, without limitation, the implied
warranties of merchantability and fitness for a particular purpose.
Daniel J. Berger