Skip to content

Instantly share code, notes, and snippets.

@ak47
Created October 3, 2011 18:03
Show Gist options
  • Save ak47/1259787 to your computer and use it in GitHub Desktop.
Save ak47/1259787 to your computer and use it in GitHub Desktop.
CSV stream with compression
def new
returned_data = Report.get_report
respond_to do |format|
format.csv{
filename = "#{Report.get_name[params[:id]]}_#{Time.now.strftime("%Y_%m_%d_%H_%M")}_#{branch]}.csv"
temp = Tempfile.new(filename)
temp << FasterCSV.generate(:force_quotes => true){ |csv| csv << returned_data[:headers]; returned_data[:data].map { |x| csv << x }; }
temp.close
`pigz #{temp.path}`
headers['Content-Encoding'] = 'gzip'
send_data File.open( temp.path + '.gz' ).read, :filename => filename, :type => 'text/csv'
}
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment