https://bugs.ruby-lang.org/https://bugs.ruby-lang.org/favicon.ico?17113305112017-10-03T00:12:03ZRuby Issue Tracking SystemRuby master - Bug #13965: Surprising behavior when using Tempfile.openhttps://bugs.ruby-lang.org/issues/13965?journal_id=670312017-10-03T00:12:03Zdavemyron (Dave Myron)
<ul></ul><p>This appears to be the behavior of <code>File.open</code> + block, as well:</p>
<pre><code>>> File.open("/tmp/test.txt","w+"){|f| (1..10000).each { |i| f.puts i }; `tail -n1 #{f.path}` }
=> "8416"
</code></pre> Ruby master - Bug #13965: Surprising behavior when using Tempfile.openhttps://bugs.ruby-lang.org/issues/13965?journal_id=670322017-10-03T00:17:34Zdavemyron (Dave Myron)
<ul></ul><p>To workaround the unexpected behavior, either use <code>IO#sync = true</code> or <code>IO#flush</code> after writing to the file.</p> Ruby master - Bug #13965: Surprising behavior when using Tempfile.openhttps://bugs.ruby-lang.org/issues/13965?journal_id=670332017-10-03T03:44:22Znobu (Nobuyoshi Nakada)nobu@ruby-lang.org
<ul><li><strong>Status</strong> changed from <i>Open</i> to <i>Rejected</i></li></ul><p>Yes, it's a nature of buffering.</p> Ruby master - Bug #13965: Surprising behavior when using Tempfile.openhttps://bugs.ruby-lang.org/issues/13965?journal_id=670532017-10-04T17:52:05Zdavemyron (Dave Myron)
<ul></ul><p>Could a small documentation blurb alleviate future headaches for other users?</p>
<p>If the docs had said something like "Due to buffering, the contents of a file may be incomplete until flushed" I would not have been (so) surprised.</p>