title: How do I get a Ruby IO stream for a Paperclip Attachment?
body: <p>I have an application that stores uploaded CSV files using the Paperclip gem.</p>
  
  <p>Once uploaded, I would like to be able to stream the data from the uploaded file into code that reads it line-by-line and loads it into a data-staging table in Postgres.</p>
  
  <p>I've gotten this far in my efforts, where <code>data_file.upload</code> is a Paperclip CSV Attachment</p>
  
  <pre><code>io = StringIO.new(Paperclip.io_adapters.for(data_file.upload).read, 'r')
  </code></pre>
  
  <p>Even though ^^ works, the problem is that - as you can see - it loads the entire file into memory as a honkin' Ruby String, and Ruby String garbage is notoriously bad for app performance.</p>
  
  <p>Instead, I want a Ruby IO object that supports use of e.g., <code>io.gets</code> so that the IO object handles buffering and cleanup, and the whole file doesn't sit as one huge string in memory.</p>
  
  <p>Thanks in advance for any suggestions!</p>