Class: Rapidmail::Utils::ZipEncoder

Inherits:
Object
  • Object
show all
Defined in:
lib/rapidmail/utils/zip_encoder.rb

Overview

Utility class for encoding files into a zip archive and then Base64 encoding the result.

Class Method Summary collapse

Class Method Details

.encode(files) ⇒ String

Encodes the given files into a zip archive and then Base64 encodes the result.

Parameters:

  • files (Hash)

    A hash where the keys are filenames and the values are file contents.

Returns:

  • (String)

    The Base64 encoded string of the zip archive.



12
13
14
15
16
17
18
19
20
21
# File 'lib/rapidmail/utils/zip_encoder.rb', line 12

def self.encode(files)
  zip_data = Zip::OutputStream.write_buffer do |zip|
    files.each do |filename, content|
      zip.put_next_entry(filename)
      zip.write content
    end
  end

  Base64.strict_encode64(zip_data.string)
end