Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

#25 ZipInputStream entries - file? and directory? don't work

open
nobody
None
5
2012-07-18
2007-08-03
Ron Newman
No

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:

!/usr/bin/ruby

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

Discussion


Anonymous


Cancel   Add attachments