module Betterzip

Constants

VERSION

Public Instance Methods

compress(zip_file_name, file_arr) click to toggle source
# File lib/betterzip.rb, line 4
def compress(zip_file_name, file_arr)
  zip_command = "zip -j public/system/#{zip_file_name}.zip #{file_arr.join(' ')}"

  raise 'Zip::WrongExitCode' unless system(zip_command)

  Rails.public_path.join('system', "#{zip_file_name}.zip")
end
compress_with_download(zip_file_name, file_arr) click to toggle source
# File lib/betterzip.rb, line 20
def compress_with_download(zip_file_name, file_arr)
  zip_command = "zip -j public/system/#{zip_file_name}.zip #{file_arr.join(' ')}"

  puts zip_command

  raise 'Zip::WrongExitCode' unless system(zip_command)

  zip_file_path = Rails.public_path.join('system', "#{zip_file_name}.zip")

  File.open(zip_file_path, 'r') do |f|
    send_data f.read, filename: "#{zip_file_name}.zip", disposition: 'attachment'
  end

  File.delete(zip_file_path)
end
send_to_download(zip_file_path, delete_flag) click to toggle source
# File lib/betterzip.rb, line 12
def send_to_download(zip_file_path, delete_flag)
  File.open(zip_file_path, 'r') do |f|
    send_data f.read, filename: "#{zip_file_path}.zip", disposition: 'attachment'
  end

  File.delete(zip_file_path) if delete_flag
end