4

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?

Gerhard
  • 6,850
  • 8
  • 51
  • 81

2 Answers2

7

According to the documentation an instance of the RubyZip ZipFile class has a comment attribute which returns the zip file's comment, if it has one.

e.g.

require 'zip/zip'

Zip::ZipFile.open('zip_with_comment.zip') do |zipfile|
  puts zipfile.comment
end
mikej
  • 65,295
  • 17
  • 152
  • 131
5

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
phloopy
  • 5,563
  • 4
  • 26
  • 37
  • What I implemented was: myzip = Zip::ZipFile.open("channel.zip") comment += myzip.find_entry("#{name}.txt").comment – Gerhard Oct 22 '09 at 05:26