rubyzip 1.1.7 → 1.2.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.
Potentially problematic release.
This version of rubyzip might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/README.md +75 -40
- data/Rakefile +3 -4
- data/lib/zip.rb +3 -5
- data/lib/zip/central_directory.rb +7 -7
- data/lib/zip/compressor.rb +0 -0
- data/lib/zip/constants.rb +2 -2
- data/lib/zip/crypto/null_encryption.rb +3 -3
- data/lib/zip/crypto/traditional_encryption.rb +5 -5
- data/lib/zip/decompressor.rb +2 -2
- data/lib/zip/deflater.rb +8 -6
- data/lib/zip/dos_time.rb +4 -5
- data/lib/zip/entry.rb +75 -81
- data/lib/zip/entry_set.rb +11 -11
- data/lib/zip/errors.rb +1 -0
- data/lib/zip/extra_field.rb +6 -6
- data/lib/zip/extra_field/generic.rb +7 -7
- data/lib/zip/extra_field/ntfs.rb +14 -16
- data/lib/zip/extra_field/old_unix.rb +9 -10
- data/lib/zip/extra_field/universal_time.rb +14 -14
- data/lib/zip/extra_field/unix.rb +8 -9
- data/lib/zip/extra_field/zip64.rb +12 -11
- data/lib/zip/extra_field/zip64_placeholder.rb +1 -1
- data/lib/zip/file.rb +47 -60
- data/lib/zip/filesystem.rb +132 -135
- data/lib/zip/inflater.rb +3 -3
- data/lib/zip/input_stream.rb +13 -7
- data/lib/zip/ioextras.rb +1 -3
- data/lib/zip/ioextras/abstract_input_stream.rb +5 -9
- data/lib/zip/ioextras/abstract_output_stream.rb +2 -4
- data/lib/zip/null_compressor.rb +2 -2
- data/lib/zip/null_decompressor.rb +3 -3
- data/lib/zip/null_input_stream.rb +0 -0
- data/lib/zip/output_stream.rb +8 -9
- data/lib/zip/pass_thru_compressor.rb +4 -4
- data/lib/zip/pass_thru_decompressor.rb +2 -3
- data/lib/zip/streamable_directory.rb +2 -2
- data/lib/zip/streamable_stream.rb +2 -2
- data/lib/zip/version.rb +1 -1
- data/samples/example.rb +29 -39
- data/samples/example_filesystem.rb +16 -18
- data/samples/example_recursive.rb +32 -25
- data/samples/{gtkRubyzip.rb → gtk_ruby_zip.rb} +23 -25
- data/samples/qtzip.rb +17 -26
- data/samples/write_simple.rb +12 -13
- data/samples/zipfind.rb +24 -32
- data/test/basic_zip_file_test.rb +11 -15
- data/test/case_sensitivity_test.rb +69 -0
- data/test/central_directory_entry_test.rb +32 -36
- data/test/central_directory_test.rb +46 -50
- data/test/crypto/null_encryption_test.rb +8 -4
- data/test/crypto/traditional_encryption_test.rb +5 -5
- data/test/data/notzippedruby.rb +1 -1
- data/test/data/oddExtraField.zip +0 -0
- data/test/data/test.xls +0 -0
- data/test/deflater_test.rb +10 -12
- data/test/encryption_test.rb +2 -2
- data/test/entry_set_test.rb +50 -25
- data/test/entry_test.rb +76 -87
- data/test/errors_test.rb +0 -2
- data/test/extra_field_test.rb +19 -21
- data/test/file_extract_directory_test.rb +12 -14
- data/test/file_extract_test.rb +33 -40
- data/test/file_permissions_test.rb +69 -0
- data/test/file_split_test.rb +24 -27
- data/test/file_test.rb +196 -172
- data/test/filesystem/dir_iterator_test.rb +13 -17
- data/test/filesystem/directory_test.rb +80 -90
- data/test/filesystem/file_mutating_test.rb +51 -63
- data/test/filesystem/file_nonmutating_test.rb +222 -228
- data/test/filesystem/file_stat_test.rb +17 -19
- data/test/gentestfiles.rb +47 -55
- data/test/inflater_test.rb +1 -1
- data/test/input_stream_test.rb +46 -34
- data/test/ioextras/abstract_input_stream_test.rb +22 -23
- data/test/ioextras/abstract_output_stream_test.rb +32 -32
- data/test/ioextras/fake_io_test.rb +1 -1
- data/test/local_entry_test.rb +36 -38
- data/test/output_stream_test.rb +20 -21
- data/test/pass_thru_compressor_test.rb +5 -6
- data/test/pass_thru_decompressor_test.rb +0 -1
- data/test/samples/example_recursive_test.rb +37 -0
- data/test/settings_test.rb +18 -15
- data/test/test_helper.rb +50 -44
- data/test/unicode_file_names_and_comments_test.rb +5 -7
- data/test/zip64_full_test.rb +9 -11
- data/test/zip64_support_test.rb +0 -1
- metadata +14 -32
@@ -1,30 +1,28 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
$: <<
|
3
|
+
$: << '../lib'
|
4
4
|
|
5
|
-
require 'zip/
|
5
|
+
require 'zip/filesystem'
|
6
6
|
|
7
|
-
EXAMPLE_ZIP =
|
7
|
+
EXAMPLE_ZIP = 'filesystem.zip'
|
8
8
|
|
9
|
-
File.delete(EXAMPLE_ZIP) if File.
|
9
|
+
File.delete(EXAMPLE_ZIP) if File.exist?(EXAMPLE_ZIP)
|
10
10
|
|
11
|
-
Zip::File.open(EXAMPLE_ZIP, Zip::File::CREATE)
|
12
|
-
|
13
|
-
zf.
|
14
|
-
zf.dir.
|
15
|
-
zf.
|
16
|
-
zf.file.
|
17
|
-
puts zf.file.read(
|
18
|
-
|
19
|
-
zf.
|
20
|
-
zf.file.open("file2.txt", "w") { |os| os.write "first file2.txt" }
|
11
|
+
Zip::File.open(EXAMPLE_ZIP, Zip::File::CREATE) do |zf|
|
12
|
+
zf.file.open('file1.txt', 'w') { |os| os.write 'first file1.txt' }
|
13
|
+
zf.dir.mkdir('dir1')
|
14
|
+
zf.dir.chdir('dir1')
|
15
|
+
zf.file.open('file1.txt', 'w') { |os| os.write 'second file1.txt' }
|
16
|
+
puts zf.file.read('file1.txt')
|
17
|
+
puts zf.file.read('../file1.txt')
|
18
|
+
zf.dir.chdir('..')
|
19
|
+
zf.file.open('file2.txt', 'w') { |os| os.write 'first file2.txt' }
|
21
20
|
puts "Entries: #{zf.entries.join(', ')}"
|
22
|
-
|
21
|
+
end
|
23
22
|
|
24
|
-
Zip::File.open(EXAMPLE_ZIP)
|
25
|
-
|zf|
|
23
|
+
Zip::File.open(EXAMPLE_ZIP) do |zf|
|
26
24
|
puts "Entries from reloaded zip: #{zf.entries.join(', ')}"
|
27
|
-
|
25
|
+
end
|
28
26
|
|
29
27
|
# For other examples, look at zip.rb and ziptest.rb
|
30
28
|
|
@@ -6,43 +6,50 @@ require 'zip'
|
|
6
6
|
# included in the archive, rather just its contents.
|
7
7
|
#
|
8
8
|
# Usage:
|
9
|
-
#
|
10
|
-
#
|
11
|
-
# zf = ZipFileGenerator.new(
|
9
|
+
# directory_to_zip = "/tmp/input"
|
10
|
+
# output_file = "/tmp/out.zip"
|
11
|
+
# zf = ZipFileGenerator.new(directory_to_zip, output_file)
|
12
12
|
# zf.write()
|
13
13
|
class ZipFileGenerator
|
14
|
-
|
15
14
|
# Initialize with the directory to zip and the location of the output archive.
|
16
|
-
def initialize(
|
17
|
-
@
|
18
|
-
@
|
15
|
+
def initialize(input_dir, output_file)
|
16
|
+
@input_dir = input_dir
|
17
|
+
@output_file = output_file
|
19
18
|
end
|
20
19
|
|
21
20
|
# Zip the input directory.
|
22
|
-
def write
|
23
|
-
entries = Dir.entries(@
|
24
|
-
io = Zip::File.open(@outputFile, Zip::File::CREATE);
|
21
|
+
def write
|
22
|
+
entries = Dir.entries(@input_dir) - %w(. ..)
|
25
23
|
|
26
|
-
|
27
|
-
|
24
|
+
::Zip::File.open(@output_file, ::Zip::File::CREATE) do |io|
|
25
|
+
write_entries entries, '', io
|
26
|
+
end
|
28
27
|
end
|
29
28
|
|
30
|
-
# A helper method to make the recursion work.
|
31
29
|
private
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
30
|
+
|
31
|
+
# A helper method to make the recursion work.
|
32
|
+
def write_entries(entries, path, io)
|
33
|
+
entries.each do |e|
|
34
|
+
zip_file_path = path == '' ? e : File.join(path, e)
|
35
|
+
disk_file_path = File.join(@input_dir, zip_file_path)
|
36
|
+
puts "Deflating #{disk_file_path}"
|
37
|
+
|
38
|
+
if File.directory? disk_file_path
|
39
|
+
recursively_deflate_directory(disk_file_path, io, zip_file_path)
|
42
40
|
else
|
43
|
-
|
41
|
+
put_into_archive(disk_file_path, io, zip_file_path)
|
44
42
|
end
|
45
|
-
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def recursively_deflate_directory(disk_file_path, io, zip_file_path)
|
47
|
+
io.mkdir zip_file_path
|
48
|
+
subdir = Dir.entries(disk_file_path) - %w(. ..)
|
49
|
+
write_entries subdir, zip_file_path, io
|
46
50
|
end
|
47
51
|
|
52
|
+
def put_into_archive(disk_file_path, io, zip_file_path)
|
53
|
+
io.add(zip_file_path, disk_file_path)
|
54
|
+
end
|
48
55
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
$: <<
|
3
|
+
$: << '../lib'
|
4
4
|
|
5
5
|
$VERBOSE = true
|
6
6
|
|
@@ -11,7 +11,7 @@ class MainApp < Gtk::Window
|
|
11
11
|
def initialize
|
12
12
|
super()
|
13
13
|
set_usize(400, 256)
|
14
|
-
set_title(
|
14
|
+
set_title('rubyzip')
|
15
15
|
signal_connect(Gtk::Window::SIGNAL_DESTROY) { Gtk.main_quit }
|
16
16
|
|
17
17
|
box = Gtk::VBox.new(false, 0)
|
@@ -19,26 +19,25 @@ class MainApp < Gtk::Window
|
|
19
19
|
|
20
20
|
@zipfile = nil
|
21
21
|
@buttonPanel = ButtonPanel.new
|
22
|
-
@buttonPanel.openButton.signal_connect(Gtk::Button::SIGNAL_CLICKED)
|
22
|
+
@buttonPanel.openButton.signal_connect(Gtk::Button::SIGNAL_CLICKED) do
|
23
23
|
show_file_selector
|
24
|
-
|
25
|
-
@buttonPanel.extractButton.signal_connect(Gtk::Button::SIGNAL_CLICKED)
|
26
|
-
puts
|
27
|
-
|
24
|
+
end
|
25
|
+
@buttonPanel.extractButton.signal_connect(Gtk::Button::SIGNAL_CLICKED) do
|
26
|
+
puts 'Not implemented!'
|
27
|
+
end
|
28
28
|
box.pack_start(@buttonPanel, false, false, 0)
|
29
29
|
|
30
30
|
sw = Gtk::ScrolledWindow.new
|
31
31
|
sw.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC)
|
32
32
|
box.pack_start(sw, true, true, 0)
|
33
33
|
|
34
|
-
@clist = Gtk::CList.new(
|
34
|
+
@clist = Gtk::CList.new(%w(Name Size Compression))
|
35
35
|
@clist.set_selection_mode(Gtk::SELECTION_BROWSE)
|
36
36
|
@clist.set_column_width(0, 120)
|
37
37
|
@clist.set_column_width(1, 120)
|
38
|
-
@clist.signal_connect(Gtk::CList::SIGNAL_SELECT_ROW)
|
39
|
-
|w, row, column, event|
|
38
|
+
@clist.signal_connect(Gtk::CList::SIGNAL_SELECT_ROW) do |_w, row, _column, _event|
|
40
39
|
@selected_row = row
|
41
|
-
|
40
|
+
end
|
42
41
|
sw.add(@clist)
|
43
42
|
end
|
44
43
|
|
@@ -48,38 +47,37 @@ class MainApp < Gtk::Window
|
|
48
47
|
super
|
49
48
|
set_layout(Gtk::BUTTONBOX_START)
|
50
49
|
set_spacing(0)
|
51
|
-
@openButton = Gtk::Button.new(
|
52
|
-
@extractButton = Gtk::Button.new(
|
50
|
+
@openButton = Gtk::Button.new('Open archive')
|
51
|
+
@extractButton = Gtk::Button.new('Extract entry')
|
53
52
|
pack_start(@openButton)
|
54
53
|
pack_start(@extractButton)
|
55
54
|
end
|
56
55
|
end
|
57
56
|
|
58
57
|
def show_file_selector
|
59
|
-
@fileSelector = Gtk::FileSelection.new(
|
58
|
+
@fileSelector = Gtk::FileSelection.new('Open zip file')
|
60
59
|
@fileSelector.show
|
61
|
-
@fileSelector.ok_button.signal_connect(Gtk::Button::SIGNAL_CLICKED)
|
60
|
+
@fileSelector.ok_button.signal_connect(Gtk::Button::SIGNAL_CLICKED) do
|
62
61
|
open_zip(@fileSelector.filename)
|
63
62
|
@fileSelector.destroy
|
64
|
-
|
65
|
-
@fileSelector.cancel_button.signal_connect(Gtk::Button::SIGNAL_CLICKED)
|
63
|
+
end
|
64
|
+
@fileSelector.cancel_button.signal_connect(Gtk::Button::SIGNAL_CLICKED) do
|
66
65
|
@fileSelector.destroy
|
67
|
-
|
66
|
+
end
|
68
67
|
end
|
69
68
|
|
70
69
|
def open_zip(filename)
|
71
70
|
@zipfile = Zip::File.open(filename)
|
72
71
|
@clist.clear
|
73
|
-
@zipfile.each
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
}
|
72
|
+
@zipfile.each do |entry|
|
73
|
+
@clist.append([entry.name,
|
74
|
+
entry.size.to_s,
|
75
|
+
(100.0 * entry.compressedSize / entry.size).to_s + '%'])
|
76
|
+
end
|
79
77
|
end
|
80
78
|
end
|
81
79
|
|
82
|
-
mainApp = MainApp.new
|
80
|
+
mainApp = MainApp.new
|
83
81
|
|
84
82
|
mainApp.show_all
|
85
83
|
|
data/samples/qtzip.rb
CHANGED
@@ -1,22 +1,18 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
$VERBOSE=true
|
3
|
+
$VERBOSE = true
|
4
4
|
|
5
|
-
$: <<
|
5
|
+
$: << '../lib'
|
6
6
|
|
7
7
|
require 'Qt'
|
8
8
|
system('rbuic -o zipdialogui.rb zipdialogui.ui')
|
9
9
|
require 'zipdialogui.rb'
|
10
10
|
require 'zip'
|
11
11
|
|
12
|
-
|
13
|
-
|
14
12
|
a = Qt::Application.new(ARGV)
|
15
13
|
|
16
14
|
class ZipDialog < ZipDialogUI
|
17
|
-
|
18
|
-
|
19
|
-
def initialize()
|
15
|
+
def initialize
|
20
16
|
super()
|
21
17
|
connect(child('add_button'), SIGNAL('clicked()'),
|
22
18
|
self, SLOT('add_files()'))
|
@@ -32,16 +28,14 @@ class ZipDialog < ZipDialogUI
|
|
32
28
|
Zip::File.foreach(@zip_filename, &proc)
|
33
29
|
end
|
34
30
|
|
35
|
-
def refresh
|
36
|
-
lv = child(
|
31
|
+
def refresh
|
32
|
+
lv = child('entry_list_view')
|
37
33
|
lv.clear
|
38
|
-
each
|
39
|
-
|e|
|
34
|
+
each do |e|
|
40
35
|
lv.insert_item(Qt::ListViewItem.new(lv, e.name, e.size.to_s))
|
41
|
-
|
36
|
+
end
|
42
37
|
end
|
43
38
|
|
44
|
-
|
45
39
|
def load(zipfile)
|
46
40
|
@zip_filename = zipfile
|
47
41
|
refresh
|
@@ -49,13 +43,11 @@ class ZipDialog < ZipDialogUI
|
|
49
43
|
|
50
44
|
def add_files
|
51
45
|
l = Qt::FileDialog.getOpenFileNames(nil, nil, self)
|
52
|
-
zipfile
|
53
|
-
|
|
54
|
-
l.each {
|
55
|
-
|path|
|
46
|
+
zipfile do |zf|
|
47
|
+
l.each do |path|
|
56
48
|
zf.add(File.basename(path), path)
|
57
|
-
|
58
|
-
|
49
|
+
end
|
50
|
+
end
|
59
51
|
refresh
|
60
52
|
end
|
61
53
|
|
@@ -63,7 +55,7 @@ class ZipDialog < ZipDialogUI
|
|
63
55
|
selected_items = []
|
64
56
|
unselected_items = []
|
65
57
|
lv_item = entry_list_view.first_child
|
66
|
-
while
|
58
|
+
while lv_item
|
67
59
|
if entry_list_view.is_selected(lv_item)
|
68
60
|
selected_items << lv_item.text(0)
|
69
61
|
else
|
@@ -77,18 +69,17 @@ class ZipDialog < ZipDialogUI
|
|
77
69
|
puts "items.size = #{items.size}"
|
78
70
|
|
79
71
|
d = Qt::FileDialog.get_existing_directory(nil, self)
|
80
|
-
if
|
81
|
-
puts
|
72
|
+
if !d
|
73
|
+
puts 'No directory chosen'
|
82
74
|
else
|
83
75
|
zipfile { |zf| items.each { |e| zf.extract(e, File.join(d, e)) } }
|
84
76
|
end
|
85
|
-
|
86
77
|
end
|
87
78
|
|
88
79
|
slots 'add_files()', 'extract_files()'
|
89
80
|
end
|
90
81
|
|
91
|
-
|
82
|
+
unless ARGV[0]
|
92
83
|
puts "usage: #{$0} zipname"
|
93
84
|
exit
|
94
85
|
end
|
@@ -97,5 +88,5 @@ zd = ZipDialog.new
|
|
97
88
|
zd.load(ARGV[0])
|
98
89
|
|
99
90
|
a.mainWidget = zd
|
100
|
-
zd.show
|
101
|
-
a.exec
|
91
|
+
zd.show
|
92
|
+
a.exec
|
data/samples/write_simple.rb
CHANGED
@@ -1,13 +1,12 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
$: <<
|
4
|
-
|
5
|
-
require 'zip'
|
6
|
-
|
7
|
-
include Zip
|
8
|
-
|
9
|
-
OutputStream.open('simple.zip')
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
}
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
$: << '../lib'
|
4
|
+
|
5
|
+
require 'zip'
|
6
|
+
|
7
|
+
include Zip
|
8
|
+
|
9
|
+
OutputStream.open('simple.zip') do |zos|
|
10
|
+
zos.put_next_entry 'entry.txt'
|
11
|
+
zos.puts 'Hello world'
|
12
|
+
end
|
data/samples/zipfind.rb
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
$VERBOSE = true
|
4
4
|
|
5
|
-
$: <<
|
5
|
+
$: << '../lib'
|
6
6
|
|
7
7
|
require 'zip'
|
8
8
|
require 'find'
|
@@ -10,53 +10,46 @@ require 'find'
|
|
10
10
|
module Zip
|
11
11
|
module ZipFind
|
12
12
|
def self.find(path, zipFilePattern = /\.zip$/i)
|
13
|
-
Find.find(path)
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
end
|
25
|
-
end
|
26
|
-
}
|
13
|
+
Find.find(path) do |fileName|
|
14
|
+
yield(fileName)
|
15
|
+
next unless zipFilePattern.match(fileName) && File.file?(fileName)
|
16
|
+
begin
|
17
|
+
Zip::File.foreach(fileName) do |zipEntry|
|
18
|
+
yield(fileName + File::SEPARATOR + zipEntry.to_s)
|
19
|
+
end
|
20
|
+
rescue Errno::EACCES => ex
|
21
|
+
puts ex
|
22
|
+
end
|
23
|
+
end
|
27
24
|
end
|
28
25
|
|
29
26
|
def self.find_file(path, fileNamePattern, zipFilePattern = /\.zip$/i)
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
}
|
27
|
+
find(path, zipFilePattern) do |fileName|
|
28
|
+
yield(fileName) if fileNamePattern.match(fileName)
|
29
|
+
end
|
34
30
|
end
|
35
|
-
|
36
31
|
end
|
37
32
|
end
|
38
33
|
|
39
34
|
if __FILE__ == $0
|
40
35
|
module ZipFindConsoleRunner
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
ZIPFILE_PATTERN_ARG_INDEX = 2;
|
36
|
+
PATH_ARG_INDEX = 0
|
37
|
+
FILENAME_PATTERN_ARG_INDEX = 1
|
38
|
+
ZIPFILE_PATTERN_ARG_INDEX = 2
|
45
39
|
|
46
40
|
def self.run(args)
|
47
41
|
check_args(args)
|
48
42
|
Zip::ZipFind.find_file(args[PATH_ARG_INDEX],
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
}
|
43
|
+
args[FILENAME_PATTERN_ARG_INDEX],
|
44
|
+
args[ZIPFILE_PATTERN_ARG_INDEX]) do |fileName|
|
45
|
+
report_entry_found fileName
|
46
|
+
end
|
54
47
|
end
|
55
48
|
|
56
49
|
def self.check_args(args)
|
57
50
|
if (args.size != 3)
|
58
|
-
|
59
|
-
|
51
|
+
usage
|
52
|
+
exit
|
60
53
|
end
|
61
54
|
end
|
62
55
|
|
@@ -67,7 +60,6 @@ if __FILE__ == $0
|
|
67
60
|
def self.report_entry_found(fileName)
|
68
61
|
puts fileName
|
69
62
|
end
|
70
|
-
|
71
63
|
end
|
72
64
|
|
73
65
|
ZipFindConsoleRunner.run(ARGV)
|
data/test/basic_zip_file_test.rb
CHANGED
@@ -5,7 +5,7 @@ class BasicZipFileTest < MiniTest::Test
|
|
5
5
|
|
6
6
|
def setup
|
7
7
|
@zip_file = ::Zip::File.new(TestZipFile::TEST_ZIP2.zip_name)
|
8
|
-
@testEntryNameIndex=0
|
8
|
+
@testEntryNameIndex = 0
|
9
9
|
end
|
10
10
|
|
11
11
|
def test_entries
|
@@ -16,26 +16,24 @@ class BasicZipFileTest < MiniTest::Test
|
|
16
16
|
def test_each
|
17
17
|
count = 0
|
18
18
|
visited = {}
|
19
|
-
@zip_file.each
|
20
|
-
|entry|
|
19
|
+
@zip_file.each do |entry|
|
21
20
|
assert(TestZipFile::TEST_ZIP2.entry_names.include?(entry.name))
|
22
21
|
assert(!visited.include?(entry.name))
|
23
22
|
visited[entry.name] = nil
|
24
23
|
count = count.succ
|
25
|
-
|
24
|
+
end
|
26
25
|
assert_equal(TestZipFile::TEST_ZIP2.entry_names.length, count)
|
27
26
|
end
|
28
27
|
|
29
28
|
def test_foreach
|
30
29
|
count = 0
|
31
30
|
visited = {}
|
32
|
-
::Zip::File.foreach(TestZipFile::TEST_ZIP2.zip_name)
|
33
|
-
|entry|
|
31
|
+
::Zip::File.foreach(TestZipFile::TEST_ZIP2.zip_name) do |entry|
|
34
32
|
assert(TestZipFile::TEST_ZIP2.entry_names.include?(entry.name))
|
35
33
|
assert(!visited.include?(entry.name))
|
36
34
|
visited[entry.name] = nil
|
37
35
|
count = count.succ
|
38
|
-
|
36
|
+
end
|
39
37
|
assert_equal(TestZipFile::TEST_ZIP2.entry_names.length, count)
|
40
38
|
end
|
41
39
|
|
@@ -51,14 +49,12 @@ class BasicZipFileTest < MiniTest::Test
|
|
51
49
|
assert_equal(TestZipFile::TEST_ZIP2.entry_names.length, count)
|
52
50
|
end
|
53
51
|
|
54
|
-
def
|
52
|
+
def test_get_input_stream_block
|
55
53
|
fileAndEntryName = @zip_file.entries.first.name
|
56
|
-
@zip_file.get_input_stream(fileAndEntryName)
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
}
|
54
|
+
@zip_file.get_input_stream(fileAndEntryName) do |zis|
|
55
|
+
assert_entry_contents_for_stream(fileAndEntryName,
|
56
|
+
zis,
|
57
|
+
fileAndEntryName)
|
58
|
+
end
|
62
59
|
end
|
63
|
-
|
64
60
|
end
|