I was trying to zip a few files and password protect them. The catch here is I cannot save the file on the disk.
I tried using Rubyzip. But seems like it doesn't support file encryption.
I tried using Zipruby but it only allows Encrypting the files already on the disk. (I am not sure about this, but I could not find a way to do it in memory).
I want to Zip and Encrypt Files in memory in Ruby.
Zipruby includes facilities to do this:
zipinmem = Zip::Archive.open_buffer(buf, Zip::CREATE) do |ar| #create zip
ar.add_buffer('bar.txt', 'baz')
end
Zip::Archive.open_buffer(zipinmem) do |ar|
ar.add_buffer('thing.txt', "We're modifying the archive in memory!")
end
See the documentation in the fifth section.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With