4 system("zip example.zip example.rb gtkRubyzip.rb")
8 ####### Using ZipInputStream alone: #######
10 Zip::ZipInputStream.open("example.zip") {
12 entry = zis.get_next_entry
13 print "First line of '#{entry.name} (#{entry.size} bytes): "
14 puts "'#{zis.gets.chomp}'"
15 entry = zis.get_next_entry
16 print "First line of '#{entry.name} (#{entry.size} bytes): "
17 puts "'#{zis.gets.chomp}'"
21 ####### Using ZipFile to read the directory of a zip file: #######
23 zf = Zip::ZipFile.new("example.zip")
27 puts "entry #{index} is #{entry.name}, size = #{entry.size}, compressed size = #{entry.compressed_size}"
28 # use zf.get_input_stream(entry) to get a ZipInputStream for the entry
29 # entry can be the ZipEntry object or any object which has a to_s method that
30 # returns the name of the entry.
34 ####### Using ZipOutputStream to write a zip file: #######
36 Zip::ZipOutputStream.open("exampleout.zip") {
38 zos.put_next_entry("the first little entry")
39 zos.puts "Hello hello hello hello hello hello hello hello hello"
41 zos.put_next_entry("the second little entry")
42 zos.puts "Hello again"
44 # Use rubyzip or your zip client of choice to verify
45 # the contents of exampleout.zip
48 ####### Using ZipFile to change a zip file: #######
50 Zip::ZipFile.open("exampleout.zip") {
52 zf.add("thisFile.rb", "example.rb")
53 zf.rename("thisFile.rb", "ILikeThisName.rb")
54 zf.add("Again", "example.rb")
58 Zip::ZipFile.open("exampleout.zip") {
60 puts "Changed zip file contains: #{zf.entries.join(', ')}"
62 puts "Without 'Again': #{zf.entries.join(', ')}"
65 # For other examples, look at zip.rb and ziptest.rb
67 # Copyright (C) 2002 Thomas Sondergaard
68 # rubyzip is free software; you can redistribute it and/or
69 # modify it under the terms of the ruby license.