ziprubyを使う

rubyでファイルのzip化を使うziprubyの使い方です
rubyzipより格段にパフォーマンスが改善されています。


gemsでインストール


gem install zipruby
サンプル

require 'zipruby'

# zipファイルのパス
file_path = File.expand_path('test.zip', 'outfile')

# zipで固めるファイルのパス
bar_file_path = File.expand_path('bar.txt', 'infile')

# zip化
Zip::Archive.open(file_path, Zip::CREATE) do |ar|
ar.add_file(bar_file_path)
end

# passwordの設定
Zip::Archive.encrypt(file_path, 'password')