Search code examples
rubyziprubyzip

Read file comments from a zip file in Ruby


I am doing Python challenge in Ruby. I need to read the file contents and comments from a Zip file. The content is no problem with the RubyZip gem but I am unable to get the comments out. Any ideas?


Solution

  • You'll actually want the comments from each of the files, which I had a much harder time finding documentation on. Here's an example of how to get the comment from a file.

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