Sha256: 6fc3ccd4e1da177a2ab5494302bb9484ad84dae13db3ad8305876b8e676faf23
Contents?: true
Size: 1002 Bytes
Versions: 1
Compression:
Stored size: 1002 Bytes
Contents
module Georgia class CompressFiles def initialize files @files = files zip! end def file @file ||= Zipfile.new("tmp-zip-#{Time.now.to_i}") end private def zip! Zip::OutputStream.open(file.path) do |output_stream| @files.each do |f| write_to_output(output_stream, f) end end file.close end def write_to_output output_stream, f filename = f.filename output_stream.put_next_entry(filename) begin data = open(f.url) rescue Errno::ENOENT => ex unless data = f.data.file raise ex end end tmp_file = Tempfile.new(filename) tmp_file.write data.read.force_encoding('UTF-8') output_stream.print IO.read(tmp_file) tmp_file.close end class Zipfile < Tempfile def filename "#{Georgia.title.try(:parameterize) || 'georgia'}_assets_#{Time.now.strftime('%Y%m%d%H%M%S')}.zip" end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
georgia-0.8.0 | app/services/georgia/compress_files.rb |