rubyoperating-systemiobufferingio-buffering

Understanding Ruby and OS I/O buffering


How does IO buffering work in Ruby? How often is data flushed to the underlying stream when using the IO and File classes? How does this compare to OS buffering? What needs to be done to guarantee that given data has been written to disk, before confidently reading it back for processing?


Solution

  • The Ruby IO documentation is not 100% clear on how this buffering works, but this is what you can extract from the documentation:

    The relevant methods to look at:

    Conclusion: flush and/or close should be enough to get the file cached so that it can be read fully by another process or operation. To get the file all the way to the physical media with certainty, you need to call IO.fsync.

    Other related methods: