If I use ZipInputStream and get_next_entry to read a zipfile, the file? and directory? and ftype methods do not work properly. (file? always returns true, directory? always returns fals, and ftype always returns "file")
If I instead use Zip::ZipFile.foreach to read the entries, these methods work correctly.
Run the following program and compare the two sets of output:
require 'rubygems'
require 'zip/zip'
filename = "/tmp/ziptest-#{Time.now.to_i}.zip"
puts "Creating #{filename}"
Zip::ZipFile.open(filename, Zip::ZipFile::CREATE) do |zf|
zf.mkdir("foo")
zf.get_output_stream("foo/bar.txt") {|io| io << "Hello.\n"}
zf.close
end
puts "Reading #{filename} with Zip::ZipInputStream.open"
Zip::ZipInputStream.open(filename) do |io|
while (entry = io.get_next_entry)
puts("#{entry.name}: file?=#{entry.file?}, directory?=#{entry.directory?}, ftype=#{entry.ftype}")
end
end
puts
puts "Reading #{filename} with Zip::ZipFile.foreach"
Zip::ZipFile.foreach(filename) do |entry|
puts("#{entry.name}: file?=#{entry.file?}, directory?=#{entry.directory?}, ftype=#{entry.ftype}")
end
Anonymous