从Ruby中的zip文件中读取文件注释

Ger*_*ard 3 ruby zip rubyzip

我在Ruby中做Python挑战.我需要从Zip文件中读取文件内容和注释.RubyZip gem 的内容没问题,但我无法得到评论.有任何想法吗?

mik*_*kej 6

根据文档,RubyZip ZipFile类的一个实例有一个comment属性,它返回zip文件的注释(如果有的话).

例如

require 'zip/zip'

Zip::ZipFile.open('zip_with_comment.zip') do |zipfile|
  puts zipfile.comment
end
Run Code Online (Sandbox Code Playgroud)


phl*_*opy 5

你真的想要每个文件的评论,我有更难找到文档.这是一个如何从文件中获取注释的示例.

require 'zip/zip'

Zip::ZipFile.open("6.zip") do |zipfile|
  p zipfile.get_entry("90052.txt").comment
end
Run Code Online (Sandbox Code Playgroud)