Harshac
Harshac

Reputation: 31

Zip and Encrypt Files in memory Ruby/Rails

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.

Upvotes: 3

Views: 1162

Answers (1)

Linuxios
Linuxios

Reputation: 35788

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.

Upvotes: 1

Related Questions