title: Ruby: Create A Gzipped Tar Archive
body: <p>What's the best way to create a gzipped tar archive with Ruby?</p>
  
  <p>I have a Rails app that needs to create a compressed archive in response to user actions. Ideally, it would be possible to write directly to a compressed file without needing to generate intermediate temp files first. The <a href="http://www.ruby-doc.org/stdlib/libdoc/zlib/rdoc/classes/Zlib.html" rel="noreferrer">Ruby Zlib</a> library appears to support direct gzip compression. How can I combine this with tar output?</p>
  
  <p>A number of quasi-solutions appear to have been proposed and a lot of information appears to be out of date.</p>
  
  <p>For example, the top Google search result for "ruby tar" gives <a href="http://www.linuxquestions.org/questions/programming-9/ruby-taring-or-ziping-with-ruby-script-520696/" rel="noreferrer">this thread</a>, which was started in 2007 with apparently no resolution.</p>
  
  <p>Another high-ranking search result is <a href="http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/32588" rel="noreferrer">this one describing ruby tar</a>. It dates back to 2002, and the announcement doesn't exactly inspire confidence.</p>
  
  <p>I've also seen various reports of shelling out to unix tar and the like.</p>
  
  <p>So, I know there are a lot of ways to do this, but I'm really looking for a recommendation to the most reliable and convenient one from someone who has tried a few of the alternatives.</p>
  
  <p>Any ideas?</p>