rubyzip/example.rb

31 lines
838 B
Ruby
Raw Normal View History

2002-01-03 01:48:31 +08:00
#!/usr/bin/env ruby
2002-01-05 08:52:47 +08:00
system("zip example.zip example.rb NEWS")
2002-01-03 01:48:31 +08:00
require 'zip'
2002-01-05 08:52:47 +08:00
## Using ZipInputStream alone:
2002-01-03 01:48:31 +08:00
ZipInputStream.open("example.zip") {
|zis|
entry = zis.getNextEntry
2002-01-05 08:52:47 +08:00
puts "********* Zip entry '#{entry.name} (#{entry.size} bytes)' contains: ********"
puts zis.read
entry = zis.getNextEntry
puts "********* Zip entry '#{entry.name} (#{entry.size} bytes)' contains: ********"
2002-01-03 01:48:31 +08:00
puts zis.read
}
2002-01-05 08:52:47 +08:00
zf = ZipFile.new("example.zip")
zf.each_with_index {
|entry, index|
puts "entry #{index} is #{entry.name}, size = #{entry.size}, compressed size = #{entry.compressedSize}"
# use zf.getInputStream(entry) to get a ZipInputStream for the entry
# entry can be the ZipEntry object or any object which has a to_s method that
# returns the name of the entry.
}
2002-01-03 01:48:31 +08:00
# For other examples, look at zip.rb and ziptest.rb