Reputation: 33
I've been trying to read the contents of a zipped file for the sake of data comparison, similar to the person from this thread: Reading files in a zip archive, without unzipping the archive
I tried the accepted code there exactly, but I'm still getting the error
/home/fikayo/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/rubyzip-1.2.0/lib/zip/file.rb:73:in `size?': no implicit conversion of Zip::Entry into String (TypeError)
For reference, here is my code:
require 'rubygems'
require 'zip'
def read_file
Zip::File.open(myZip) do |zip_file|
zip_file.each do |entry|
if entry.directory?
puts "#{entry.name} is a folder!"
elsif entry.symlink?
puts "#{entry.name} is a symlink!"
elsif entry.file?
puts "#{entry.name} is a regular file!"
# Read into memory
content = entry.get_input_stream.read
# Output
puts content
else
puts "No sell"
end
end
end
end
myZip
is the variable that I stored the zip file inside. I checked to make sure and its type is listed as Zip::Entry
Upvotes: 1
Views: 1356
Reputation: 1434
According to the rubyzip documentation (and the question you linked) mZip
should be of class String
and contain the path to a file rather than File
or Zip::Entry
.
mZip = './folder/file.zip'
def read_file
Zip::File.open(myZip) do |zip_file|
#...
end
Upvotes: 3