rubyzip 1.1.7 → 2.3.2

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.
Files changed (101) hide show
  1. checksums.yaml +5 -5
  2. data/README.md +137 -54
  3. data/Rakefile +6 -4
  4. data/lib/zip/central_directory.rb +17 -13
  5. data/lib/zip/compressor.rb +1 -2
  6. data/lib/zip/constants.rb +57 -5
  7. data/lib/zip/crypto/decrypted_io.rb +40 -0
  8. data/lib/zip/crypto/null_encryption.rb +4 -6
  9. data/lib/zip/crypto/traditional_encryption.rb +14 -14
  10. data/lib/zip/decompressor.rb +22 -4
  11. data/lib/zip/deflater.rb +8 -6
  12. data/lib/zip/dos_time.rb +17 -13
  13. data/lib/zip/entry.rb +171 -148
  14. data/lib/zip/entry_set.rb +16 -14
  15. data/lib/zip/errors.rb +3 -0
  16. data/lib/zip/extra_field/generic.rb +14 -13
  17. data/lib/zip/extra_field/ntfs.rb +18 -16
  18. data/lib/zip/extra_field/old_unix.rb +12 -11
  19. data/lib/zip/extra_field/universal_time.rb +46 -16
  20. data/lib/zip/extra_field/unix.rb +10 -9
  21. data/lib/zip/extra_field/zip64.rb +15 -12
  22. data/lib/zip/extra_field/zip64_placeholder.rb +1 -2
  23. data/lib/zip/extra_field.rb +18 -16
  24. data/lib/zip/file.rb +147 -115
  25. data/lib/zip/filesystem.rb +289 -272
  26. data/lib/zip/inflater.rb +24 -36
  27. data/lib/zip/input_stream.rb +44 -28
  28. data/lib/zip/ioextras/abstract_input_stream.rb +24 -17
  29. data/lib/zip/ioextras/abstract_output_stream.rb +4 -6
  30. data/lib/zip/ioextras.rb +2 -4
  31. data/lib/zip/null_compressor.rb +2 -2
  32. data/lib/zip/null_decompressor.rb +3 -11
  33. data/lib/zip/null_input_stream.rb +0 -0
  34. data/lib/zip/output_stream.rb +25 -17
  35. data/lib/zip/pass_thru_compressor.rb +6 -6
  36. data/lib/zip/pass_thru_decompressor.rb +14 -24
  37. data/lib/zip/streamable_directory.rb +3 -3
  38. data/lib/zip/streamable_stream.rb +7 -11
  39. data/lib/zip/version.rb +1 -1
  40. data/lib/zip.rb +15 -6
  41. data/samples/example.rb +29 -39
  42. data/samples/example_filesystem.rb +16 -18
  43. data/samples/example_recursive.rb +31 -25
  44. data/samples/gtk_ruby_zip.rb +84 -0
  45. data/samples/qtzip.rb +23 -32
  46. data/samples/write_simple.rb +10 -13
  47. data/samples/zipfind.rb +33 -40
  48. metadata +50 -141
  49. data/samples/gtkRubyzip.rb +0 -86
  50. data/test/basic_zip_file_test.rb +0 -64
  51. data/test/central_directory_entry_test.rb +0 -73
  52. data/test/central_directory_test.rb +0 -104
  53. data/test/crypto/null_encryption_test.rb +0 -53
  54. data/test/crypto/traditional_encryption_test.rb +0 -80
  55. data/test/data/WarnInvalidDate.zip +0 -0
  56. data/test/data/file1.txt +0 -46
  57. data/test/data/file1.txt.deflatedData +0 -0
  58. data/test/data/file2.txt +0 -1504
  59. data/test/data/globTest/foo/bar/baz/foo.txt +0 -0
  60. data/test/data/globTest/foo.txt +0 -0
  61. data/test/data/globTest/food.txt +0 -0
  62. data/test/data/globTest.zip +0 -0
  63. data/test/data/mimetype +0 -1
  64. data/test/data/notzippedruby.rb +0 -7
  65. data/test/data/ntfs.zip +0 -0
  66. data/test/data/rubycode.zip +0 -0
  67. data/test/data/rubycode2.zip +0 -0
  68. data/test/data/testDirectory.bin +0 -0
  69. data/test/data/zip64-sample.zip +0 -0
  70. data/test/data/zipWithDirs.zip +0 -0
  71. data/test/data/zipWithEncryption.zip +0 -0
  72. data/test/deflater_test.rb +0 -67
  73. data/test/encryption_test.rb +0 -42
  74. data/test/entry_set_test.rb +0 -138
  75. data/test/entry_test.rb +0 -165
  76. data/test/errors_test.rb +0 -36
  77. data/test/extra_field_test.rb +0 -78
  78. data/test/file_extract_directory_test.rb +0 -56
  79. data/test/file_extract_test.rb +0 -90
  80. data/test/file_split_test.rb +0 -60
  81. data/test/file_test.rb +0 -559
  82. data/test/filesystem/dir_iterator_test.rb +0 -62
  83. data/test/filesystem/directory_test.rb +0 -131
  84. data/test/filesystem/file_mutating_test.rb +0 -100
  85. data/test/filesystem/file_nonmutating_test.rb +0 -514
  86. data/test/filesystem/file_stat_test.rb +0 -66
  87. data/test/gentestfiles.rb +0 -134
  88. data/test/inflater_test.rb +0 -14
  89. data/test/input_stream_test.rb +0 -170
  90. data/test/ioextras/abstract_input_stream_test.rb +0 -103
  91. data/test/ioextras/abstract_output_stream_test.rb +0 -106
  92. data/test/ioextras/fake_io_test.rb +0 -18
  93. data/test/local_entry_test.rb +0 -156
  94. data/test/output_stream_test.rb +0 -129
  95. data/test/pass_thru_compressor_test.rb +0 -31
  96. data/test/pass_thru_decompressor_test.rb +0 -15
  97. data/test/settings_test.rb +0 -92
  98. data/test/test_helper.rb +0 -228
  99. data/test/unicode_file_names_and_comments_test.rb +0 -52
  100. data/test/zip64_full_test.rb +0 -53
  101. data/test/zip64_support_test.rb +0 -15
@@ -1,13 +1,8 @@
1
1
  module Zip
2
- class StreamableStream < DelegateClass(Entry) #nodoc:all
2
+ class StreamableStream < DelegateClass(Entry) # :nodoc:all
3
3
  def initialize(entry)
4
4
  super(entry)
5
- dirname = if zipfile.is_a?(::String)
6
- ::File.dirname(zipfile)
7
- else
8
- '.'
9
- end
10
- @temp_file = Tempfile.new(::File.basename(name), dirname)
5
+ @temp_file = Tempfile.new(::File.basename(name))
11
6
  @temp_file.binmode
12
7
  end
13
8
 
@@ -24,9 +19,10 @@ module Zip
24
19
  end
25
20
 
26
21
  def get_input_stream
27
- if !@temp_file.closed?
22
+ unless @temp_file.closed?
28
23
  raise StandardError, "cannot open entry for reading while its open for writing - #{name}"
29
24
  end
25
+
30
26
  @temp_file.open # reopens tempfile from top
31
27
  @temp_file.binmode
32
28
  if block_given?
@@ -40,9 +36,9 @@ module Zip
40
36
  end
41
37
  end
42
38
 
43
- def write_to_zip_output_stream(aZipOutputStream)
44
- aZipOutputStream.put_next_entry(self)
45
- get_input_stream { |is| ::Zip::IOExtras.copy_stream(aZipOutputStream, is) }
39
+ def write_to_zip_output_stream(output_stream)
40
+ output_stream.put_next_entry(self)
41
+ get_input_stream { |is| ::Zip::IOExtras.copy_stream(output_stream, is) }
46
42
  end
47
43
 
48
44
  def clean_up
data/lib/zip/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Zip
2
- VERSION = '1.1.7'
2
+ VERSION = '2.3.2'
3
3
  end
data/lib/zip.rb CHANGED
@@ -1,9 +1,11 @@
1
+ require 'English'
1
2
  require 'delegate'
2
3
  require 'singleton'
3
4
  require 'tempfile'
4
5
  require 'fileutils'
5
6
  require 'stringio'
6
7
  require 'zlib'
8
+ require 'zip/constants'
7
9
  require 'zip/dos_time'
8
10
  require 'zip/ioextras'
9
11
  require 'rbconfig'
@@ -21,6 +23,7 @@ require 'zip/null_compressor'
21
23
  require 'zip/null_input_stream'
22
24
  require 'zip/pass_thru_compressor'
23
25
  require 'zip/pass_thru_decompressor'
26
+ require 'zip/crypto/decrypted_io'
24
27
  require 'zip/crypto/encryption'
25
28
  require 'zip/crypto/null_encryption'
26
29
  require 'zip/crypto/traditional_encryption'
@@ -28,16 +31,20 @@ require 'zip/inflater'
28
31
  require 'zip/deflater'
29
32
  require 'zip/streamable_stream'
30
33
  require 'zip/streamable_directory'
31
- require 'zip/constants'
32
34
  require 'zip/errors'
33
- if defined? JRUBY_VERSION
34
- require 'jruby'
35
- JRuby.objectspace = true
36
- end
37
35
 
38
36
  module Zip
39
37
  extend self
40
- attr_accessor :unicode_names, :on_exists_proc, :continue_on_exists_proc, :sort_entries, :default_compression, :write_zip64_support, :warn_invalid_date
38
+ attr_accessor :unicode_names,
39
+ :on_exists_proc,
40
+ :continue_on_exists_proc,
41
+ :sort_entries,
42
+ :default_compression,
43
+ :write_zip64_support,
44
+ :warn_invalid_date,
45
+ :case_insensitive_match,
46
+ :force_entry_names_encoding,
47
+ :validate_entry_sizes
41
48
 
42
49
  def reset!
43
50
  @_ran_once = false
@@ -48,6 +55,8 @@ module Zip
48
55
  @default_compression = ::Zlib::DEFAULT_COMPRESSION
49
56
  @write_zip64_support = false
50
57
  @warn_invalid_date = true
58
+ @case_insensitive_match = false
59
+ @validate_entry_sizes = true
51
60
  end
52
61
 
53
62
  def setup
data/samples/example.rb CHANGED
@@ -1,89 +1,79 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- $: << "../lib"
4
- system("zip example.zip example.rb gtkRubyzip.rb")
3
+ $LOAD_PATH << '../lib'
4
+ system('zip example.zip example.rb gtk_ruby_zip.rb')
5
5
 
6
6
  require 'zip'
7
7
 
8
8
  ####### Using ZipInputStream alone: #######
9
9
 
10
- Zip::InputStream.open("example.zip") {
11
- |zis|
10
+ Zip::InputStream.open('example.zip') do |zis|
12
11
  entry = zis.get_next_entry
13
12
  print "First line of '#{entry.name} (#{entry.size} bytes): "
14
13
  puts "'#{zis.gets.chomp}'"
15
14
  entry = zis.get_next_entry
16
15
  print "First line of '#{entry.name} (#{entry.size} bytes): "
17
16
  puts "'#{zis.gets.chomp}'"
18
- }
19
-
17
+ end
20
18
 
21
19
  ####### Using ZipFile to read the directory of a zip file: #######
22
20
 
23
- zf = Zip::File.new("example.zip")
24
- zf.each_with_index {
25
- |entry, index|
26
-
21
+ zf = Zip::File.new('example.zip')
22
+ zf.each_with_index do |entry, index|
27
23
  puts "entry #{index} is #{entry.name}, size = #{entry.size}, compressed size = #{entry.compressed_size}"
28
24
  # use zf.get_input_stream(entry) to get a ZipInputStream for the entry
29
25
  # entry can be the ZipEntry object or any object which has a to_s method that
30
26
  # returns the name of the entry.
31
- }
32
-
27
+ end
33
28
 
34
29
  ####### Using ZipOutputStream to write a zip file: #######
35
30
 
36
- Zip::OutputStream.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"
31
+ Zip::OutputStream.open('exampleout.zip') do |zos|
32
+ zos.put_next_entry('the first little entry')
33
+ zos.puts 'Hello hello hello hello hello hello hello hello hello'
40
34
 
41
- zos.put_next_entry("the second little entry")
42
- zos.puts "Hello again"
35
+ zos.put_next_entry('the second little entry')
36
+ zos.puts 'Hello again'
43
37
 
44
38
  # Use rubyzip or your zip client of choice to verify
45
39
  # the contents of exampleout.zip
46
- }
40
+ end
47
41
 
48
42
  ####### Using ZipFile to change a zip file: #######
49
43
 
50
- Zip::File.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
- }
44
+ Zip::File.open('exampleout.zip') do |zip_file|
45
+ zip_file.add('thisFile.rb', 'example.rb')
46
+ zip_file.rename('thisFile.rb', 'ILikeThisName.rb')
47
+ zip_file.add('Again', 'example.rb')
48
+ end
56
49
 
57
50
  # Lets check
58
- Zip::File.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
- }
51
+ Zip::File.open('exampleout.zip') do |zip_file|
52
+ puts "Changed zip file contains: #{zip_file.entries.join(', ')}"
53
+ zip_file.remove('Again')
54
+ puts "Without 'Again': #{zip_file.entries.join(', ')}"
55
+ end
64
56
 
65
57
  ####### Using ZipFile to split a zip file: #######
66
58
 
67
59
  # Creating large zip file for splitting
68
- Zip::OutputStream.open("large_zip_file.zip") do |zos|
69
- puts "Creating zip file..."
60
+ Zip::OutputStream.open('large_zip_file.zip') do |zos|
61
+ puts 'Creating zip file...'
70
62
  10.times do |i|
71
63
  zos.put_next_entry("large_entry_#{i}.txt")
72
- zos.puts "Hello" * 104857600
64
+ zos.puts 'Hello' * 104_857_600
73
65
  end
74
66
  end
75
67
 
76
68
  # Splitting created large zip file
77
- part_zips_count = Zip::File.split("large_zip_file.zip", 2097152, false)
69
+ part_zips_count = Zip::File.split('large_zip_file.zip', 2_097_152, false)
78
70
  puts "Zip file splitted in #{part_zips_count} parts"
79
71
 
80
72
  # Track splitting an archive
81
- Zip::File.split("large_zip_file.zip", 1048576, true, 'part_zip_file') do
82
- |part_count, part_index, chunk_bytes, segment_bytes|
83
- puts "#{part_index} of #{part_count} part splitting: #{(chunk_bytes.to_f/segment_bytes.to_f * 100).to_i}%"
73
+ Zip::File.split('large_zip_file.zip', 1_048_576, true, 'part_zip_file') do |part_count, part_index, chunk_bytes, segment_bytes|
74
+ puts "#{part_index} of #{part_count} part splitting: #{(chunk_bytes.to_f / segment_bytes * 100).to_i}%"
84
75
  end
85
76
 
86
-
87
77
  # For other examples, look at zip.rb and ziptest.rb
88
78
 
89
79
  # Copyright (C) 2002 Thomas Sondergaard
@@ -1,30 +1,28 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- $: << "../lib"
3
+ $LOAD_PATH << '../lib'
4
4
 
5
- require 'zip/zipfilesystem'
5
+ require 'zip/filesystem'
6
6
 
7
- EXAMPLE_ZIP = "filesystem.zip"
7
+ EXAMPLE_ZIP = 'filesystem.zip'
8
8
 
9
- File.delete(EXAMPLE_ZIP) if File.exists?(EXAMPLE_ZIP)
9
+ File.delete(EXAMPLE_ZIP) if File.exist?(EXAMPLE_ZIP)
10
10
 
11
- Zip::File.open(EXAMPLE_ZIP, Zip::File::CREATE) {
12
- |zf|
13
- zf.file.open("file1.txt", "w") { |os| os.write "first file1.txt" }
14
- zf.dir.mkdir("dir1")
15
- zf.dir.chdir("dir1")
16
- zf.file.open("file1.txt", "w") { |os| os.write "second file1.txt" }
17
- puts zf.file.read("file1.txt")
18
- puts zf.file.read("../file1.txt")
19
- zf.dir.chdir("..")
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,49 @@ require 'zip'
6
6
  # included in the archive, rather just its contents.
7
7
  #
8
8
  # Usage:
9
- # directoryToZip = "/tmp/input"
10
- # outputFile = "/tmp/out.zip"
11
- # zf = ZipFileGenerator.new(directoryToZip, outputFile)
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(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 |zipfile|
25
+ write_entries entries, '', zipfile
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, zipfile)
33
+ entries.each do |e|
34
+ zipfile_path = path == '' ? e : File.join(path, e)
35
+ disk_file_path = File.join(@input_dir, zipfile_path)
36
+
37
+ if File.directory? disk_file_path
38
+ recursively_deflate_directory(disk_file_path, zipfile, zipfile_path)
42
39
  else
43
- io.get_output_stream(zipFilePath) { |f| f.puts(File.open(diskFilePath, "rb").read())}
40
+ put_into_archive(disk_file_path, zipfile, zipfile_path)
44
41
  end
45
- }
42
+ end
43
+ end
44
+
45
+ def recursively_deflate_directory(disk_file_path, zipfile, zipfile_path)
46
+ zipfile.mkdir zipfile_path
47
+ subdir = Dir.entries(disk_file_path) - %w[. ..]
48
+ write_entries subdir, zipfile_path, zipfile
46
49
  end
47
50
 
51
+ def put_into_archive(disk_file_path, zipfile, zipfile_path)
52
+ zipfile.add(zipfile_path, disk_file_path)
53
+ end
48
54
  end
@@ -0,0 +1,84 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $LOAD_PATH << '../lib'
4
+
5
+ $VERBOSE = true
6
+
7
+ require 'gtk'
8
+ require '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
+ @button_panel = ButtonPanel.new
22
+ @button_panel.open_button.signal_connect(Gtk::Button::SIGNAL_CLICKED) do
23
+ show_file_selector
24
+ end
25
+ @button_panel.extract_button.signal_connect(Gtk::Button::SIGNAL_CLICKED) do
26
+ puts 'Not implemented!'
27
+ end
28
+ box.pack_start(@button_panel, 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(%w[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) do |_w, row, _column, _event|
39
+ @selected_row = row
40
+ end
41
+ sw.add(@clist)
42
+ end
43
+
44
+ class ButtonPanel < Gtk::HButtonBox
45
+ attr_reader :open_button, :extract_button
46
+ def initialize
47
+ super
48
+ set_layout(Gtk::BUTTONBOX_START)
49
+ set_spacing(0)
50
+ @open_button = Gtk::Button.new('Open archive')
51
+ @extract_button = Gtk::Button.new('Extract entry')
52
+ pack_start(@open_button)
53
+ pack_start(@extract_button)
54
+ end
55
+ end
56
+
57
+ def show_file_selector
58
+ @file_selector = Gtk::FileSelection.new('Open zip file')
59
+ @file_selector.show
60
+ @file_selector.ok_button.signal_connect(Gtk::Button::SIGNAL_CLICKED) do
61
+ open_zip(@file_selector.filename)
62
+ @file_selector.destroy
63
+ end
64
+ @file_selector.cancel_button.signal_connect(Gtk::Button::SIGNAL_CLICKED) do
65
+ @file_selector.destroy
66
+ end
67
+ end
68
+
69
+ def open_zip(filename)
70
+ @zipfile = Zip::File.open(filename)
71
+ @clist.clear
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
77
+ end
78
+ end
79
+
80
+ main_app = MainApp.new
81
+
82
+ main_app.show_all
83
+
84
+ Gtk.main
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
- $: << "../lib"
5
+ $LOAD_PATH << '../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()'))
@@ -24,24 +20,22 @@ class ZipDialog < ZipDialogUI
24
20
  self, SLOT('extract_files()'))
25
21
  end
26
22
 
27
- def zipfile(&proc)
28
- Zip::File.open(@zip_filename, &proc)
23
+ def zipfile(&a_proc)
24
+ Zip::File.open(@zip_filename, &a_proc)
29
25
  end
30
26
 
31
- def each(&proc)
32
- Zip::File.foreach(@zip_filename, &proc)
27
+ def each(&a_proc)
28
+ Zip::File.foreach(@zip_filename, &a_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
@@ -73,23 +65,22 @@ class ZipDialog < ZipDialogUI
73
65
  end
74
66
  puts "selected_items.size = #{selected_items.size}"
75
67
  puts "unselected_items.size = #{unselected_items.size}"
76
- items = selected_items.size > 0 ? selected_items : unselected_items
68
+ items = !selected_items.empty? ? selected_items : unselected_items
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]
92
- puts "usage: #{$0} zipname"
82
+ unless ARGV[0]
83
+ puts "usage: #{$PROGRAM_NAME} zipname"
93
84
  exit
94
85
  end
95
86
 
@@ -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,10 @@
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
+ $LOAD_PATH << '../lib'
4
+
5
+ require 'zip'
6
+
7
+ ::Zip::OutputStream.open('simple.zip') do |zos|
8
+ zos.put_next_entry 'entry.txt'
9
+ zos.puts 'Hello world'
10
+ end