viva-rubyzip 0.9.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/ChangeLog +1081 -0
- data/NEWS +144 -0
- data/README +72 -0
- data/Rakefile +110 -0
- data/TODO +16 -0
- data/install.rb +22 -0
- data/lib/zip/ioextras.rb +158 -0
- data/lib/zip/stdrubyext.rb +111 -0
- data/lib/zip/tempfile_bugfixed.rb +195 -0
- data/lib/zip/zip.rb +1854 -0
- data/lib/zip/zipfilesystem.rb +609 -0
- data/lib/zip/ziprequire.rb +90 -0
- data/samples/example.rb +69 -0
- data/samples/example_filesystem.rb +34 -0
- data/samples/gtkRubyzip.rb +86 -0
- data/samples/qtzip.rb +101 -0
- data/samples/write_simple.rb +13 -0
- data/samples/zipfind.rb +74 -0
- data/test/alltests.rb +9 -0
- data/test/data/file1.txt +46 -0
- data/test/data/file1.txt.deflatedData +0 -0
- data/test/data/file2.txt +1504 -0
- data/test/data/notzippedruby.rb +7 -0
- data/test/data/rubycode.zip +0 -0
- data/test/data/rubycode2.zip +0 -0
- data/test/data/testDirectory.bin +0 -0
- data/test/data/zipWithDirs.zip +0 -0
- data/test/gentestfiles.rb +157 -0
- data/test/ioextrastest.rb +208 -0
- data/test/stdrubyexttest.rb +52 -0
- data/test/zipfilesystemtest.rb +831 -0
- data/test/ziprequiretest.rb +43 -0
- data/test/ziptest.rb +1690 -0
- metadata +87 -0
data/samples/example.rb
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
$: << "../lib"
|
4
|
+
system("zip example.zip example.rb gtkRubyzip.rb")
|
5
|
+
|
6
|
+
require 'zip/zip'
|
7
|
+
|
8
|
+
####### Using ZipInputStream alone: #######
|
9
|
+
|
10
|
+
Zip::ZipInputStream.open("example.zip") {
|
11
|
+
|zis|
|
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}'"
|
18
|
+
}
|
19
|
+
|
20
|
+
|
21
|
+
####### Using ZipFile to read the directory of a zip file: #######
|
22
|
+
|
23
|
+
zf = Zip::ZipFile.new("example.zip")
|
24
|
+
zf.each_with_index {
|
25
|
+
|entry, index|
|
26
|
+
|
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.
|
31
|
+
}
|
32
|
+
|
33
|
+
|
34
|
+
####### Using ZipOutputStream to write a zip file: #######
|
35
|
+
|
36
|
+
Zip::ZipOutputStream.open("exampleout.zip") {
|
37
|
+
|zos|
|
38
|
+
zos.put_next_entry("the first little entry")
|
39
|
+
zos.puts "Hello hello hello hello hello hello hello hello hello"
|
40
|
+
|
41
|
+
zos.put_next_entry("the second little entry")
|
42
|
+
zos.puts "Hello again"
|
43
|
+
|
44
|
+
# Use rubyzip or your zip client of choice to verify
|
45
|
+
# the contents of exampleout.zip
|
46
|
+
}
|
47
|
+
|
48
|
+
####### Using ZipFile to change a zip file: #######
|
49
|
+
|
50
|
+
Zip::ZipFile.open("exampleout.zip") {
|
51
|
+
|zf|
|
52
|
+
zf.add("thisFile.rb", "example.rb")
|
53
|
+
zf.rename("thisFile.rb", "ILikeThisName.rb")
|
54
|
+
zf.add("Again", "example.rb")
|
55
|
+
}
|
56
|
+
|
57
|
+
# Lets check
|
58
|
+
Zip::ZipFile.open("exampleout.zip") {
|
59
|
+
|zf|
|
60
|
+
puts "Changed zip file contains: #{zf.entries.join(', ')}"
|
61
|
+
zf.remove("Again")
|
62
|
+
puts "Without 'Again': #{zf.entries.join(', ')}"
|
63
|
+
}
|
64
|
+
|
65
|
+
# For other examples, look at zip.rb and ziptest.rb
|
66
|
+
|
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.
|
@@ -0,0 +1,34 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
$: << "../lib"
|
4
|
+
|
5
|
+
require 'zip/zipfilesystem'
|
6
|
+
require 'fileutils'
|
7
|
+
|
8
|
+
EXAMPLE_ZIP = "filesystem.zip"
|
9
|
+
|
10
|
+
File.delete(EXAMPLE_ZIP) if File.exists?(EXAMPLE_ZIP)
|
11
|
+
|
12
|
+
Zip::ZipFile.open(EXAMPLE_ZIP, Zip::ZipFile::CREATE) {
|
13
|
+
|zf|
|
14
|
+
zf.file.open("file1.txt", "w") { |os| os.write "first file1.txt" }
|
15
|
+
zf.dir.mkdir("dir1")
|
16
|
+
zf.dir.chdir("dir1")
|
17
|
+
zf.file.open("file1.txt", "w") { |os| os.write "second file1.txt" }
|
18
|
+
puts zf.file.read("file1.txt")
|
19
|
+
puts zf.file.read("../file1.txt")
|
20
|
+
zf.dir.chdir("..")
|
21
|
+
zf.file.open("file2.txt", "w") { |os| os.write "first file2.txt" }
|
22
|
+
puts "Entries: #{zf.entries.join(', ')}"
|
23
|
+
}
|
24
|
+
|
25
|
+
Zip::ZipFile.open(EXAMPLE_ZIP) {
|
26
|
+
|zf|
|
27
|
+
puts "Entries from reloaded zip: #{zf.entries.join(', ')}"
|
28
|
+
}
|
29
|
+
|
30
|
+
# For other examples, look at zip.rb and ziptest.rb
|
31
|
+
|
32
|
+
# Copyright (C) 2003 Thomas Sondergaard
|
33
|
+
# rubyzip is free software; you can redistribute it and/or
|
34
|
+
# modify it under the terms of the ruby license.
|
@@ -0,0 +1,86 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
$: << "../lib"
|
4
|
+
|
5
|
+
$VERBOSE = true
|
6
|
+
|
7
|
+
require 'gtk'
|
8
|
+
require 'zip/zip'
|
9
|
+
|
10
|
+
class MainApp < Gtk::Window
|
11
|
+
def initialize
|
12
|
+
super()
|
13
|
+
set_usize(400, 256)
|
14
|
+
set_title("rubyzip")
|
15
|
+
signal_connect(Gtk::Window::SIGNAL_DESTROY) { Gtk.main_quit }
|
16
|
+
|
17
|
+
box = Gtk::VBox.new(false, 0)
|
18
|
+
add(box)
|
19
|
+
|
20
|
+
@zipfile = nil
|
21
|
+
@buttonPanel = ButtonPanel.new
|
22
|
+
@buttonPanel.openButton.signal_connect(Gtk::Button::SIGNAL_CLICKED) {
|
23
|
+
show_file_selector
|
24
|
+
}
|
25
|
+
@buttonPanel.extractButton.signal_connect(Gtk::Button::SIGNAL_CLICKED) {
|
26
|
+
puts "Not implemented!"
|
27
|
+
}
|
28
|
+
box.pack_start(@buttonPanel, false, false, 0)
|
29
|
+
|
30
|
+
sw = Gtk::ScrolledWindow.new
|
31
|
+
sw.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC)
|
32
|
+
box.pack_start(sw, true, true, 0)
|
33
|
+
|
34
|
+
@clist = Gtk::CList.new(["Name", "Size", "Compression"])
|
35
|
+
@clist.set_selection_mode(Gtk::SELECTION_BROWSE)
|
36
|
+
@clist.set_column_width(0, 120)
|
37
|
+
@clist.set_column_width(1, 120)
|
38
|
+
@clist.signal_connect(Gtk::CList::SIGNAL_SELECT_ROW) {
|
39
|
+
|w, row, column, event|
|
40
|
+
@selected_row = row
|
41
|
+
}
|
42
|
+
sw.add(@clist)
|
43
|
+
end
|
44
|
+
|
45
|
+
class ButtonPanel < Gtk::HButtonBox
|
46
|
+
attr_reader :openButton, :extractButton
|
47
|
+
def initialize
|
48
|
+
super
|
49
|
+
set_layout(Gtk::BUTTONBOX_START)
|
50
|
+
set_spacing(0)
|
51
|
+
@openButton = Gtk::Button.new("Open archive")
|
52
|
+
@extractButton = Gtk::Button.new("Extract entry")
|
53
|
+
pack_start(@openButton)
|
54
|
+
pack_start(@extractButton)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def show_file_selector
|
59
|
+
@fileSelector = Gtk::FileSelection.new("Open zip file")
|
60
|
+
@fileSelector.show
|
61
|
+
@fileSelector.ok_button.signal_connect(Gtk::Button::SIGNAL_CLICKED) {
|
62
|
+
open_zip(@fileSelector.filename)
|
63
|
+
@fileSelector.destroy
|
64
|
+
}
|
65
|
+
@fileSelector.cancel_button.signal_connect(Gtk::Button::SIGNAL_CLICKED) {
|
66
|
+
@fileSelector.destroy
|
67
|
+
}
|
68
|
+
end
|
69
|
+
|
70
|
+
def open_zip(filename)
|
71
|
+
@zipfile = Zip::ZipFile.open(filename)
|
72
|
+
@clist.clear
|
73
|
+
@zipfile.each {
|
74
|
+
|entry|
|
75
|
+
@clist.append([ entry.name,
|
76
|
+
entry.size.to_s,
|
77
|
+
(100.0*entry.compressedSize/entry.size).to_s+"%" ])
|
78
|
+
}
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
mainApp = MainApp.new()
|
83
|
+
|
84
|
+
mainApp.show_all
|
85
|
+
|
86
|
+
Gtk.main
|
data/samples/qtzip.rb
ADDED
@@ -0,0 +1,101 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
$VERBOSE=true
|
4
|
+
|
5
|
+
$: << "../lib"
|
6
|
+
|
7
|
+
require 'Qt'
|
8
|
+
system('rbuic -o zipdialogui.rb zipdialogui.ui')
|
9
|
+
require 'zipdialogui.rb'
|
10
|
+
require 'zip/zip'
|
11
|
+
|
12
|
+
|
13
|
+
|
14
|
+
a = Qt::Application.new(ARGV)
|
15
|
+
|
16
|
+
class ZipDialog < ZipDialogUI
|
17
|
+
|
18
|
+
|
19
|
+
def initialize()
|
20
|
+
super()
|
21
|
+
connect(child('add_button'), SIGNAL('clicked()'),
|
22
|
+
self, SLOT('add_files()'))
|
23
|
+
connect(child('extract_button'), SIGNAL('clicked()'),
|
24
|
+
self, SLOT('extract_files()'))
|
25
|
+
end
|
26
|
+
|
27
|
+
def zipfile(&proc)
|
28
|
+
Zip::ZipFile.open(@zip_filename, &proc)
|
29
|
+
end
|
30
|
+
|
31
|
+
def each(&proc)
|
32
|
+
Zip::ZipFile.foreach(@zip_filename, &proc)
|
33
|
+
end
|
34
|
+
|
35
|
+
def refresh()
|
36
|
+
lv = child("entry_list_view")
|
37
|
+
lv.clear
|
38
|
+
each {
|
39
|
+
|e|
|
40
|
+
lv.insert_item(Qt::ListViewItem.new(lv, e.name, e.size.to_s))
|
41
|
+
}
|
42
|
+
end
|
43
|
+
|
44
|
+
|
45
|
+
def load(zipfile)
|
46
|
+
@zip_filename = zipfile
|
47
|
+
refresh
|
48
|
+
end
|
49
|
+
|
50
|
+
def add_files
|
51
|
+
l = Qt::FileDialog.getOpenFileNames(nil, nil, self)
|
52
|
+
zipfile {
|
53
|
+
|zf|
|
54
|
+
l.each {
|
55
|
+
|path|
|
56
|
+
zf.add(File.basename(path), path)
|
57
|
+
}
|
58
|
+
}
|
59
|
+
refresh
|
60
|
+
end
|
61
|
+
|
62
|
+
def extract_files
|
63
|
+
selected_items = []
|
64
|
+
unselected_items = []
|
65
|
+
lv_item = entry_list_view.first_child
|
66
|
+
while (lv_item)
|
67
|
+
if entry_list_view.is_selected(lv_item)
|
68
|
+
selected_items << lv_item.text(0)
|
69
|
+
else
|
70
|
+
unselected_items << lv_item.text(0)
|
71
|
+
end
|
72
|
+
lv_item = lv_item.next_sibling
|
73
|
+
end
|
74
|
+
puts "selected_items.size = #{selected_items.size}"
|
75
|
+
puts "unselected_items.size = #{unselected_items.size}"
|
76
|
+
items = selected_items.size > 0 ? selected_items : unselected_items
|
77
|
+
puts "items.size = #{items.size}"
|
78
|
+
|
79
|
+
d = Qt::FileDialog.get_existing_directory(nil, self)
|
80
|
+
if (!d)
|
81
|
+
puts "No directory chosen"
|
82
|
+
else
|
83
|
+
zipfile { |zf| items.each { |e| zf.extract(e, File.join(d, e)) } }
|
84
|
+
end
|
85
|
+
|
86
|
+
end
|
87
|
+
|
88
|
+
slots 'add_files()', 'extract_files()'
|
89
|
+
end
|
90
|
+
|
91
|
+
if !ARGV[0]
|
92
|
+
puts "usage: #{$0} zipname"
|
93
|
+
exit
|
94
|
+
end
|
95
|
+
|
96
|
+
zd = ZipDialog.new
|
97
|
+
zd.load(ARGV[0])
|
98
|
+
|
99
|
+
a.mainWidget = zd
|
100
|
+
zd.show()
|
101
|
+
a.exec()
|
data/samples/zipfind.rb
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
$VERBOSE = true
|
4
|
+
|
5
|
+
$: << "../lib"
|
6
|
+
|
7
|
+
require 'zip/zip'
|
8
|
+
require 'find'
|
9
|
+
|
10
|
+
module Zip
|
11
|
+
module ZipFind
|
12
|
+
def self.find(path, zipFilePattern = /\.zip$/i)
|
13
|
+
Find.find(path) {
|
14
|
+
|fileName|
|
15
|
+
yield(fileName)
|
16
|
+
if zipFilePattern.match(fileName) && File.file?(fileName)
|
17
|
+
begin
|
18
|
+
Zip::ZipFile.foreach(fileName) {
|
19
|
+
|zipEntry|
|
20
|
+
yield(fileName + File::SEPARATOR + zipEntry.to_s)
|
21
|
+
}
|
22
|
+
rescue Errno::EACCES => ex
|
23
|
+
puts ex
|
24
|
+
end
|
25
|
+
end
|
26
|
+
}
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.find_file(path, fileNamePattern, zipFilePattern = /\.zip$/i)
|
30
|
+
self.find(path, zipFilePattern) {
|
31
|
+
|fileName|
|
32
|
+
yield(fileName) if fileNamePattern.match(fileName)
|
33
|
+
}
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
if __FILE__ == $0
|
40
|
+
module ZipFindConsoleRunner
|
41
|
+
|
42
|
+
PATH_ARG_INDEX = 0;
|
43
|
+
FILENAME_PATTERN_ARG_INDEX = 1;
|
44
|
+
ZIPFILE_PATTERN_ARG_INDEX = 2;
|
45
|
+
|
46
|
+
def self.run(args)
|
47
|
+
check_args(args)
|
48
|
+
Zip::ZipFind.find_file(args[PATH_ARG_INDEX],
|
49
|
+
args[FILENAME_PATTERN_ARG_INDEX],
|
50
|
+
args[ZIPFILE_PATTERN_ARG_INDEX]) {
|
51
|
+
|fileName|
|
52
|
+
report_entry_found fileName
|
53
|
+
}
|
54
|
+
end
|
55
|
+
|
56
|
+
def self.check_args(args)
|
57
|
+
if (args.size != 3)
|
58
|
+
usage
|
59
|
+
exit
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def self.usage
|
64
|
+
puts "Usage: #{$0} PATH ZIPFILENAME_PATTERN FILNAME_PATTERN"
|
65
|
+
end
|
66
|
+
|
67
|
+
def self.report_entry_found(fileName)
|
68
|
+
puts fileName
|
69
|
+
end
|
70
|
+
|
71
|
+
end
|
72
|
+
|
73
|
+
ZipFindConsoleRunner.run(ARGV)
|
74
|
+
end
|
data/test/alltests.rb
ADDED
data/test/data/file1.txt
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
|
2
|
+
AUTOMAKE_OPTIONS = gnu
|
3
|
+
|
4
|
+
EXTRA_DIST = test.zip
|
5
|
+
|
6
|
+
CXXFLAGS= -g
|
7
|
+
|
8
|
+
noinst_LIBRARIES = libzipios.a
|
9
|
+
|
10
|
+
bin_PROGRAMS = test_zip test_izipfilt test_izipstream
|
11
|
+
# test_flist
|
12
|
+
|
13
|
+
libzipios_a_SOURCES = backbuffer.h fcol.cpp fcol.h \
|
14
|
+
fcol_common.h fcolexceptions.cpp fcolexceptions.h \
|
15
|
+
fileentry.cpp fileentry.h flist.cpp \
|
16
|
+
flist.h flistentry.cpp flistentry.h \
|
17
|
+
flistscanner.h ifiltstreambuf.cpp ifiltstreambuf.h \
|
18
|
+
inflatefilt.cpp inflatefilt.h izipfilt.cpp \
|
19
|
+
izipfilt.h izipstream.cpp izipstream.h \
|
20
|
+
zipfile.cpp zipfile.h ziphead.cpp \
|
21
|
+
ziphead.h flistscanner.ll
|
22
|
+
|
23
|
+
# test_flist_SOURCES = test_flist.cpp
|
24
|
+
|
25
|
+
test_izipfilt_SOURCES = test_izipfilt.cpp
|
26
|
+
|
27
|
+
test_izipstream_SOURCES = test_izipstream.cpp
|
28
|
+
|
29
|
+
test_zip_SOURCES = test_zip.cpp
|
30
|
+
|
31
|
+
# Notice that libzipios.a is not specified as -L. -lzipios
|
32
|
+
# If it was, automake would not include it as a dependency.
|
33
|
+
|
34
|
+
# test_flist_LDADD = libzipios.a
|
35
|
+
|
36
|
+
test_izipfilt_LDADD = libzipios.a -lz
|
37
|
+
|
38
|
+
test_zip_LDADD = libzipios.a -lz
|
39
|
+
|
40
|
+
test_izipstream_LDADD = libzipios.a -lz
|
41
|
+
|
42
|
+
|
43
|
+
|
44
|
+
flistscanner.cc : flistscanner.ll
|
45
|
+
$(LEX) -+ -PFListScanner -o$@ $^
|
46
|
+
|
Binary file
|