【问题标题】:Read file comments from a zip file in Ruby从 Ruby 中的 zip 文件中读取文件注释
【发布时间】:2009-10-19 11:48:22
【问题描述】:

我正在用 Ruby 做Python challenge。我需要从 Zip 文件中读取文件内容和 cmets。 RubyZip gem 的内容没有问题,但我无法取出 cmets。有什么想法吗?

【问题讨论】:

    标签: ruby zip rubyzip


    【解决方案1】:

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

    例如

    require 'zip/zip'
    
    Zip::ZipFile.open('zip_with_comment.zip') do |zipfile|
      puts zipfile.comment
    end
    

    【讨论】:

      【解决方案2】:

      您实际上会想要每个文件中的 cmets,而我很难找到 documentation on。下面是一个如何从文件中获取评论的示例。

      require 'zip/zip'
      
      Zip::ZipFile.open("6.zip") do |zipfile|
        p zipfile.get_entry("90052.txt").comment
      end
      

      【讨论】:

      • 我实现的是:myzip = Zip::ZipFile.open("channel.zip") comment += myzip.find_entry("#{name}.txt").comment
      猜你喜欢
      • 2019-12-06
      • 1970-01-01
      • 1970-01-01
      • 2012-03-09
      • 2016-06-15
      • 2013-03-18
      • 2021-12-15
      • 2020-12-04
      相关资源
      最近更新 更多