title: writing to the middle of a file in ruby
body: <p>I've opened a file in ruby with the options a+. I can seek to the middle of the file and read from it but when I try to write the writes always go to the end. How do I write to a position in the middle?</p>
  
  <pre><code>jpg = File.new("/tmp/bot.jpg", "a+")
  jpg.seek 24
  puts jpg.getc.chr
  jpg.seek 24
  jpg.write "R" 
  jpg.seek 28
  jpg.write "W" 
  puts jpg.pos
  jpg.close
  </code></pre>
  
  <p>The R and W both end up at the end of the file.</p>
  
  <p>I know I can only overwrite existing bytes, that is ok, that is what I want to do.</p>