Ruby中的压缩和解压缩的使用

来源:互联网 发布:网络打鱼 编辑:程序博客网 时间:2024/05/01 08:47

直接上代码

#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/

0 0
原创粉丝点击