rubyzip 1.1.7 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of rubyzip might be problematic. Click here for more details.

Files changed (87) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +69 -32
  3. data/Rakefile +3 -4
  4. data/lib/zip.rb +3 -5
  5. data/lib/zip/central_directory.rb +7 -7
  6. data/lib/zip/compressor.rb +0 -0
  7. data/lib/zip/constants.rb +2 -2
  8. data/lib/zip/crypto/null_encryption.rb +3 -3
  9. data/lib/zip/crypto/traditional_encryption.rb +5 -5
  10. data/lib/zip/decompressor.rb +2 -2
  11. data/lib/zip/deflater.rb +8 -6
  12. data/lib/zip/dos_time.rb +4 -5
  13. data/lib/zip/entry.rb +68 -80
  14. data/lib/zip/entry_set.rb +11 -11
  15. data/lib/zip/errors.rb +1 -0
  16. data/lib/zip/extra_field.rb +6 -6
  17. data/lib/zip/extra_field/generic.rb +7 -7
  18. data/lib/zip/extra_field/ntfs.rb +14 -16
  19. data/lib/zip/extra_field/old_unix.rb +9 -10
  20. data/lib/zip/extra_field/universal_time.rb +14 -14
  21. data/lib/zip/extra_field/unix.rb +8 -9
  22. data/lib/zip/extra_field/zip64.rb +12 -11
  23. data/lib/zip/extra_field/zip64_placeholder.rb +1 -1
  24. data/lib/zip/file.rb +45 -49
  25. data/lib/zip/filesystem.rb +132 -135
  26. data/lib/zip/inflater.rb +3 -3
  27. data/lib/zip/input_stream.rb +13 -7
  28. data/lib/zip/ioextras.rb +1 -3
  29. data/lib/zip/ioextras/abstract_input_stream.rb +5 -9
  30. data/lib/zip/ioextras/abstract_output_stream.rb +0 -2
  31. data/lib/zip/null_compressor.rb +2 -2
  32. data/lib/zip/null_decompressor.rb +3 -3
  33. data/lib/zip/null_input_stream.rb +0 -0
  34. data/lib/zip/output_stream.rb +8 -9
  35. data/lib/zip/pass_thru_compressor.rb +4 -4
  36. data/lib/zip/pass_thru_decompressor.rb +2 -3
  37. data/lib/zip/streamable_directory.rb +2 -2
  38. data/lib/zip/streamable_stream.rb +2 -2
  39. data/lib/zip/version.rb +1 -1
  40. data/samples/example.rb +29 -39
  41. data/samples/example_filesystem.rb +16 -18
  42. data/samples/example_recursive.rb +33 -24
  43. data/samples/{gtkRubyzip.rb → gtk_ruby_zip.rb} +23 -25
  44. data/samples/qtzip.rb +17 -26
  45. data/samples/write_simple.rb +12 -13
  46. data/samples/zipfind.rb +24 -32
  47. data/test/basic_zip_file_test.rb +11 -15
  48. data/test/case_sensitivity_test.rb +69 -0
  49. data/test/central_directory_entry_test.rb +31 -35
  50. data/test/central_directory_test.rb +46 -50
  51. data/test/crypto/null_encryption_test.rb +2 -2
  52. data/test/crypto/traditional_encryption_test.rb +5 -5
  53. data/test/data/notzippedruby.rb +1 -1
  54. data/test/data/oddExtraField.zip +0 -0
  55. data/test/data/test.xls +0 -0
  56. data/test/deflater_test.rb +10 -12
  57. data/test/encryption_test.rb +2 -2
  58. data/test/entry_set_test.rb +38 -24
  59. data/test/entry_test.rb +76 -78
  60. data/test/errors_test.rb +0 -2
  61. data/test/extra_field_test.rb +19 -21
  62. data/test/file_extract_directory_test.rb +12 -14
  63. data/test/file_extract_test.rb +33 -40
  64. data/test/file_permissions_test.rb +69 -0
  65. data/test/file_split_test.rb +24 -27
  66. data/test/file_test.rb +174 -170
  67. data/test/filesystem/dir_iterator_test.rb +13 -17
  68. data/test/filesystem/directory_test.rb +80 -90
  69. data/test/filesystem/file_mutating_test.rb +51 -63
  70. data/test/filesystem/file_nonmutating_test.rb +222 -228
  71. data/test/filesystem/file_stat_test.rb +17 -19
  72. data/test/gentestfiles.rb +43 -55
  73. data/test/inflater_test.rb +1 -1
  74. data/test/input_stream_test.rb +42 -30
  75. data/test/ioextras/abstract_input_stream_test.rb +21 -22
  76. data/test/ioextras/abstract_output_stream_test.rb +32 -32
  77. data/test/local_entry_test.rb +35 -37
  78. data/test/output_stream_test.rb +20 -21
  79. data/test/pass_thru_compressor_test.rb +5 -6
  80. data/test/pass_thru_decompressor_test.rb +0 -1
  81. data/test/samples/example_recursive_test.rb +37 -0
  82. data/test/settings_test.rb +18 -15
  83. data/test/test_helper.rb +37 -44
  84. data/test/unicode_file_names_and_comments_test.rb +5 -7
  85. data/test/zip64_full_test.rb +9 -11
  86. data/test/zip64_support_test.rb +0 -1
  87. metadata +14 -32
@@ -7,42 +7,51 @@ require 'zip'
7
7
  #
8
8
  # Usage:
9
9
  # directoryToZip = "/tmp/input"
10
- # outputFile = "/tmp/out.zip"
11
- # zf = ZipFileGenerator.new(directoryToZip, outputFile)
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(inputDir, outputFile)
17
- @inputDir = inputDir
18
- @outputFile = outputFile
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(@inputDir); entries.delete("."); entries.delete("..")
24
- io = Zip::File.open(@outputFile, Zip::File::CREATE);
21
+ def write
22
+ entries = Dir.entries(@input_dir) - %w(. ..)
25
23
 
26
- writeEntries(entries, "", io)
27
- io.close();
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
- def writeEntries(entries, path, io)
33
-
34
- entries.each { |e|
35
- zipFilePath = path == "" ? e : File.join(path, e)
36
- diskFilePath = File.join(@inputDir, zipFilePath)
37
- puts "Deflating " + diskFilePath
38
- if File.directory?(diskFilePath)
39
- io.mkdir(zipFilePath)
40
- subdir =Dir.entries(diskFilePath); subdir.delete("."); subdir.delete("..")
41
- writeEntries(subdir, zipFilePath, io)
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
- io.get_output_stream(zipFilePath) { |f| f.puts(File.open(diskFilePath, "rb").read())}
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.get_output_stream(zip_file_path) do |f|
54
+ f.write(File.open(disk_file_path, 'rb').read)
55
+ end
56
+ end
48
57
  end
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- $: << "../lib"
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("rubyzip")
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 "Not implemented!"
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(["Name", "Size", "Compression"])
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("Open archive")
52
- @extractButton = Gtk::Button.new("Extract entry")
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("Open zip file")
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
- |entry|
75
- @clist.append([ entry.name,
76
- entry.size.to_s,
77
- (100.0*entry.compressedSize/entry.size).to_s+"%" ])
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
 
@@ -1,22 +1,18 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- $VERBOSE=true
3
+ $VERBOSE = true
4
4
 
5
- $: << "../lib"
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("entry_list_view")
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
- |zf|
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 (lv_item)
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 (!d)
81
- puts "No directory chosen"
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
- if !ARGV[0]
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
@@ -1,13 +1,12 @@
1
- #!/usr/bin/env ruby
2
-
3
- $: << "../lib"
4
-
5
- require 'zip'
6
-
7
- include Zip
8
-
9
- OutputStream.open('simple.zip') {
10
- |zos|
11
- ze = zos.put_next_entry 'entry.txt'
12
- zos.puts "Hello world"
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
@@ -2,7 +2,7 @@
2
2
 
3
3
  $VERBOSE = true
4
4
 
5
- $: << "../lib"
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
- |fileName|
15
- yield(fileName)
16
- if zipFilePattern.match(fileName) && File.file?(fileName)
17
- begin
18
- Zip::File.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
- }
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
- self.find(path, zipFilePattern) {
31
- |fileName|
32
- yield(fileName) if fileNamePattern.match(fileName)
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
- PATH_ARG_INDEX = 0;
43
- FILENAME_PATTERN_ARG_INDEX = 1;
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
- args[FILENAME_PATTERN_ARG_INDEX],
50
- args[ZIPFILE_PATTERN_ARG_INDEX]) {
51
- |fileName|
52
- report_entry_found fileName
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
- usage
59
- exit
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)
@@ -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 test_get_input_streamBlock
52
+ def test_get_input_stream_block
55
53
  fileAndEntryName = @zip_file.entries.first.name
56
- @zip_file.get_input_stream(fileAndEntryName) {
57
- |zis|
58
- assert_entryContentsForStream(fileAndEntryName,
59
- zis,
60
- fileAndEntryName)
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