Upgraded rubyzip to 0.5.8
This commit is contained in:
parent
ee876a2907
commit
f776807dff
37 changed files with 1513 additions and 710 deletions
69
vendor/rubyzip-0.5.8/samples/example.rb
vendored
Normal file
69
vendor/rubyzip-0.5.8/samples/example.rb
vendored
Normal file
|
@ -0,0 +1,69 @@
|
|||
#!/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.
|
34
vendor/rubyzip-0.5.8/samples/example_filesystem.rb
vendored
Normal file
34
vendor/rubyzip-0.5.8/samples/example_filesystem.rb
vendored
Normal file
|
@ -0,0 +1,34 @@
|
|||
#!/usr/bin/env ruby
|
||||
|
||||
$: << "../lib"
|
||||
|
||||
require 'zip/zipfilesystem'
|
||||
require 'ftools'
|
||||
|
||||
EXAMPLE_ZIP = "filesystem.zip"
|
||||
|
||||
File.delete(EXAMPLE_ZIP) if File.exists?(EXAMPLE_ZIP)
|
||||
|
||||
Zip::ZipFile.open(EXAMPLE_ZIP, Zip::ZipFile::CREATE) {
|
||||
|zf|
|
||||
zf.file.open("file1.txt", "w") { |os| os.write "first file1.txt" }
|
||||
zf.dir.mkdir("dir1")
|
||||
zf.dir.chdir("dir1")
|
||||
zf.file.open("file1.txt", "w") { |os| os.write "second file1.txt" }
|
||||
puts zf.file.read("file1.txt")
|
||||
puts zf.file.read("../file1.txt")
|
||||
zf.dir.chdir("..")
|
||||
zf.file.open("file2.txt", "w") { |os| os.write "first file2.txt" }
|
||||
puts "Entries: #{zf.entries.join(', ')}"
|
||||
}
|
||||
|
||||
Zip::ZipFile.open(EXAMPLE_ZIP) {
|
||||
|zf|
|
||||
puts "Entries from reloaded zip: #{zf.entries.join(', ')}"
|
||||
}
|
||||
|
||||
# For other examples, look at zip.rb and ziptest.rb
|
||||
|
||||
# Copyright (C) 2003 Thomas Sondergaard
|
||||
# rubyzip is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the ruby license.
|
86
vendor/rubyzip-0.5.8/samples/gtkRubyzip.rb
vendored
Normal file
86
vendor/rubyzip-0.5.8/samples/gtkRubyzip.rb
vendored
Normal file
|
@ -0,0 +1,86 @@
|
|||
#!/usr/bin/env ruby
|
||||
|
||||
$: << "../lib"
|
||||
|
||||
$VERBOSE = true
|
||||
|
||||
require 'gtk'
|
||||
require 'zip/zip'
|
||||
|
||||
class MainApp < Gtk::Window
|
||||
def initialize
|
||||
super()
|
||||
set_usize(400, 256)
|
||||
set_title("rubyzip")
|
||||
signal_connect(Gtk::Window::SIGNAL_DESTROY) { Gtk.main_quit }
|
||||
|
||||
box = Gtk::VBox.new(false, 0)
|
||||
add(box)
|
||||
|
||||
@zipfile = nil
|
||||
@buttonPanel = ButtonPanel.new
|
||||
@buttonPanel.openButton.signal_connect(Gtk::Button::SIGNAL_CLICKED) {
|
||||
show_file_selector
|
||||
}
|
||||
@buttonPanel.extractButton.signal_connect(Gtk::Button::SIGNAL_CLICKED) {
|
||||
puts "Not implemented!"
|
||||
}
|
||||
box.pack_start(@buttonPanel, false, false, 0)
|
||||
|
||||
sw = Gtk::ScrolledWindow.new
|
||||
sw.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC)
|
||||
box.pack_start(sw, true, true, 0)
|
||||
|
||||
@clist = Gtk::CList.new(["Name", "Size", "Compression"])
|
||||
@clist.set_selection_mode(Gtk::SELECTION_BROWSE)
|
||||
@clist.set_column_width(0, 120)
|
||||
@clist.set_column_width(1, 120)
|
||||
@clist.signal_connect(Gtk::CList::SIGNAL_SELECT_ROW) {
|
||||
|w, row, column, event|
|
||||
@selected_row = row
|
||||
}
|
||||
sw.add(@clist)
|
||||
end
|
||||
|
||||
class ButtonPanel < Gtk::HButtonBox
|
||||
attr_reader :openButton, :extractButton
|
||||
def initialize
|
||||
super
|
||||
set_layout(Gtk::BUTTONBOX_START)
|
||||
set_spacing(0)
|
||||
@openButton = Gtk::Button.new("Open archive")
|
||||
@extractButton = Gtk::Button.new("Extract entry")
|
||||
pack_start(@openButton)
|
||||
pack_start(@extractButton)
|
||||
end
|
||||
end
|
||||
|
||||
def show_file_selector
|
||||
@fileSelector = Gtk::FileSelection.new("Open zip file")
|
||||
@fileSelector.show
|
||||
@fileSelector.ok_button.signal_connect(Gtk::Button::SIGNAL_CLICKED) {
|
||||
open_zip(@fileSelector.filename)
|
||||
@fileSelector.destroy
|
||||
}
|
||||
@fileSelector.cancel_button.signal_connect(Gtk::Button::SIGNAL_CLICKED) {
|
||||
@fileSelector.destroy
|
||||
}
|
||||
end
|
||||
|
||||
def open_zip(filename)
|
||||
@zipfile = Zip::ZipFile.open(filename)
|
||||
@clist.clear
|
||||
@zipfile.each {
|
||||
|entry|
|
||||
@clist.append([ entry.name,
|
||||
entry.size.to_s,
|
||||
(100.0*entry.compressedSize/entry.size).to_s+"%" ])
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
mainApp = MainApp.new()
|
||||
|
||||
mainApp.show_all
|
||||
|
||||
Gtk.main
|
13
vendor/rubyzip-0.5.8/samples/write_simple.rb
vendored
Normal file
13
vendor/rubyzip-0.5.8/samples/write_simple.rb
vendored
Normal file
|
@ -0,0 +1,13 @@
|
|||
#!/usr/bin/env ruby
|
||||
|
||||
$: << "../lib"
|
||||
|
||||
require 'zip/zip'
|
||||
|
||||
include Zip
|
||||
|
||||
ZipOutputStream.open('simple.zip') {
|
||||
|zos|
|
||||
ze = zos.put_next_entry 'entry.txt'
|
||||
zos.puts "Hello world"
|
||||
}
|
74
vendor/rubyzip-0.5.8/samples/zipfind.rb
vendored
Normal file
74
vendor/rubyzip-0.5.8/samples/zipfind.rb
vendored
Normal file
|
@ -0,0 +1,74 @@
|
|||
#!/usr/bin/env ruby
|
||||
|
||||
$VERBOSE = true
|
||||
|
||||
$: << "../lib"
|
||||
|
||||
require 'zip/zip'
|
||||
require 'find'
|
||||
|
||||
module Zip
|
||||
module ZipFind
|
||||
def self.find(path, zipFilePattern = /\.zip$/i)
|
||||
Find.find(path) {
|
||||
|fileName|
|
||||
yield(fileName)
|
||||
if zipFilePattern.match(fileName) && File.file?(fileName)
|
||||
begin
|
||||
Zip::ZipFile.foreach(fileName) {
|
||||
|zipEntry|
|
||||
yield(fileName + File::SEPARATOR + zipEntry.to_s)
|
||||
}
|
||||
rescue Errno::EACCES => ex
|
||||
puts ex
|
||||
end
|
||||
end
|
||||
}
|
||||
end
|
||||
|
||||
def self.find_file(path, fileNamePattern, zipFilePattern = /\.zip$/i)
|
||||
self.find(path, zipFilePattern) {
|
||||
|fileName|
|
||||
yield(fileName) if fileNamePattern.match(fileName)
|
||||
}
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
if __FILE__ == $0
|
||||
module ZipFindConsoleRunner
|
||||
|
||||
PATH_ARG_INDEX = 0;
|
||||
FILENAME_PATTERN_ARG_INDEX = 1;
|
||||
ZIPFILE_PATTERN_ARG_INDEX = 2;
|
||||
|
||||
def self.run(args)
|
||||
check_args(args)
|
||||
Zip::ZipFind.find_file(args[PATH_ARG_INDEX],
|
||||
args[FILENAME_PATTERN_ARG_INDEX],
|
||||
args[ZIPFILE_PATTERN_ARG_INDEX]) {
|
||||
|fileName|
|
||||
report_entry_found fileName
|
||||
}
|
||||
end
|
||||
|
||||
def self.check_args(args)
|
||||
if (args.size != 3)
|
||||
usage
|
||||
exit
|
||||
end
|
||||
end
|
||||
|
||||
def self.usage
|
||||
puts "Usage: #{$0} PATH ZIPFILENAME_PATTERN FILNAME_PATTERN"
|
||||
end
|
||||
|
||||
def self.report_entry_found(fileName)
|
||||
puts fileName
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
ZipFindConsoleRunner.run(ARGV)
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue