Created
October 3, 2011 18:03
-
-
Save ak47/1259787 to your computer and use it in GitHub Desktop.
CSV stream with compression
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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