Menu

#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
Anonymous

Add attachments
Cancel





Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.