Sha256: 3901716964294c8b925f5699cda8db5117437f71e1d6c8129a9bba05c2790f0e

Contents?: true

Size: 1.86 KB

Versions: 36

Compression:

Stored size: 1.86 KB

Contents

#!/usr/bin/env ruby

$: << "../lib"
system("zip example.zip example.rb gtkRubyzip.rb")

require 'zip/zip'

####### Using ZipInputStream alone: #######

Zip::ZipInputStream.open("example.zip") {
  |zis|
  entry = zis.get_next_entry
  print "First line of '#{entry.name} (#{entry.size} bytes):  "
  puts "'#{zis.gets.chomp}'"
  entry = zis.get_next_entry
  print "First line of '#{entry.name} (#{entry.size} bytes):  "
  puts "'#{zis.gets.chomp}'"
}


####### Using ZipFile to read the directory of a zip file: #######

zf = Zip::ZipFile.new("example.zip")
zf.each_with_index {
  |entry, index|
  
  puts "entry #{index} is #{entry.name}, size = #{entry.size}, compressed size = #{entry.compressed_size}"
  # use zf.get_input_stream(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.
}


####### Using ZipOutputStream to write a zip file: #######

Zip::ZipOutputStream.open("exampleout.zip") {
  |zos|
  zos.put_next_entry("the first little entry")
  zos.puts "Hello hello hello hello hello hello hello hello hello"

  zos.put_next_entry("the second little entry")
  zos.puts "Hello again"

  # Use rubyzip or your zip client of choice to verify
  # the contents of exampleout.zip
}

####### Using ZipFile to change a zip file: #######

Zip::ZipFile.open("exampleout.zip") {
  |zf|
  zf.add("thisFile.rb", "example.rb")
  zf.rename("thisFile.rb", "ILikeThisName.rb")
  zf.add("Again", "example.rb")
}

# Lets check
Zip::ZipFile.open("exampleout.zip") {
  |zf|
  puts "Changed zip file contains: #{zf.entries.join(', ')}"
  zf.remove("Again")
  puts "Without 'Again': #{zf.entries.join(', ')}"
}

# For other examples, look at zip.rb and ziptest.rb

# Copyright (C) 2002 Thomas Sondergaard
# rubyzip is free software; you can redistribute it and/or
# modify it under the terms of the ruby license.

Version data entries

36 entries across 36 versions & 14 rubygems

Version Path
IronDigital-rubyzip-0.9.2 samples/example.rb
agraham-rubyzip-0.9.1 samples/example.rb
erawk-rubyzip-0.9.1 samples/example.rb
erawk-rubyzip-0.9.2 samples/example.rb
expectedbehavior-rubyzip-0.9.1.2 samples/example.rb
febeling-rubyzip-0.9.2 samples/example.rb
mksm-rubyzip-0.9.3 samples/example.rb
sunrise-cms-0.5.0.rc1 vendor/bundle/ruby/1.9.1/gems/rubyzip-0.9.9/samples/example.rb
sunrise-cms-0.3.3 vendor/bundle/ruby/1.9.1/gems/rubyzip-0.9.8/samples/example.rb
sunrise-cms-0.3.2 vendor/bundle/ruby/1.9.1/gems/rubyzip-0.9.8/samples/example.rb
sunrise-cms-0.3.1 vendor/bundle/ruby/1.9.1/gems/rubyzip-0.9.8/samples/example.rb
sunrise-cms-0.3.0 vendor/bundle/ruby/1.9.1/gems/rubyzip-0.9.8/samples/example.rb
rubyzip-0.9.9 samples/example.rb
sunrise-cms-0.3.0.rc vendor/bundle/ruby/1.9.1/gems/rubyzip-0.9.8/samples/example.rb
rubyzip-0.9.8 samples/example.rb
rubyzip-0.9.7 samples/example.rb
frameworks-capybara-0.2.0.rc6 vendor/bundle/ruby/1.8/gems/rubyzip-0.9.6.1/samples/example.rb
frameworks-capybara-0.2.0.rc5 vendor/bundle/ruby/1.8/gems/rubyzip-0.9.6.1/samples/example.rb
frameworks-capybara-0.2.0.rc4 vendor/bundle/ruby/1.8/gems/rubyzip-0.9.6.1/samples/example.rb
frameworks-capybara-0.2.0.rc3 vendor/bundle/ruby/1.8/gems/rubyzip-0.9.6.1/samples/example.rb