Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Password protected zip file with csv/json data inside
compressed_filestream = Zip::OutputStream.write_buffer(::StringIO.new(''), Zip::TraditionalEncrypter.new('password')) do |zos|
#First file
zos.put_next_entry "test1.csv"
csv = CSV.generate do |csv|
User.all.each do |user|
csv << [user.id, user.name]
end
csv << values
end
zos.print csv
#Second file
zos.put_next_entry "test2.csv"
zos.print current_user.to_json
end
compressed_filestream.rewind
send_data compressed_filestream.read, filename: "test.zip"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment