尝试使用rubyzip向一个zip文件添加注释,否则我根本不会修改该文件。
zf = Zip::ZipFile.open 'Archive.zip'
zf.comment = "blah blah blah"我尝试过zf.close和zf.commit,但没有成功。我在通读文档,但我似乎找不到解决方案。
以前有人这么做过吗?
发布于 2012-04-08 07:15:04
升级到RubyZip 0.9.7 (今天发布),它修复了这个错误。
发布于 2012-04-07 06:06:41
我用下面的代码成功地尝试了一下:
require 'zip/zipfilesystem'
zf = Zip::ZipFile.open 'Archive.zip', 'w'
zf.comment = "blah blah blah"
zf.get_output_stream("first.txt") { |f| f.puts "Hello from ZipFile" }
zf.close我至少添加了一个文档来创建zip文件。没有内容,就没有zip文件(仅有注释似乎不是内容)。
你不需要创建zip,你想要修改一个zip文件。
这也可以工作,但它还会更改zip-file:
require 'zip/zipfilesystem'
zf = Zip::ZipFile.open 'Archive.zip'
zf.comment = "CHANGED COMMENT"
zf.get_output_stream("second.txt") { |f| f.puts "Hello from ZipFile" }
zf.close基于此,您可以执行以下操作:
require 'zip/zipfilesystem'
zf = Zip::ZipFile.open 'Archive.zip'
zf.comment = "CHANGED COMMENT"
zf.get_output_stream("second.txt") { |f| f.puts "Hello from ZipFile" }
zf.commit #write the data and change the commen
zf.remove("second.txt") #remove the data again - the comment changed
zf.closehttps://stackoverflow.com/questions/10049627
复制相似问题