直接上代码
#The following example opens zip archive my.zip (creating it if it doesn‘t exist) and adds an entry first.txt and a directory entry a_dir to it.
gem 'rubyzip'
require 'zip'
Zip::File.open("test.zip", Zip::File::CREATE) {
|zipfile|
zipfile.get_output_stream("first.txt") { |f| f.puts "Hello from ZipFi2222222222le" }
#zipfile.mkdir("a_dir")
}
#The next example reopens my.zip writes the contents of first.txt to standard out and deletes the entry from the archive.
Zip::File.open("test.zip", Zip::File::CREATE) {
|zipfile|
zipfile.each do |zent|
puts zent
puts zipfile.read(zent)
#zipfile.remove("first.txt")
end
}
可以参考的文档和下载ZIP包的路径:
http://rubyzip.sourceforge.net/
http://rubyzip.sourceforge.net/classes/Zip/ZipFile.html
http://sourceforge.net/projects/rubyzip/files/rubyzip/