Last active
May 25, 2024 10:32
-
-
Save aquajach/7fde54aa9bc1ac03740feb154e53eb7d to your computer and use it in GitHub Desktop.
Password protected zip file with csv/json data inside
This file contains hidden or 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
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