rubyzip 1.0.0 → 1.2.0
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 +6 -14
 - data/README.md +173 -42
 - data/Rakefile +10 -5
 - data/TODO +0 -1
 - data/lib/zip/central_directory.rb +55 -24
 - data/lib/zip/compressor.rb +0 -0
 - data/lib/zip/constants.rb +4 -2
 - data/lib/zip/crypto/encryption.rb +11 -0
 - data/lib/zip/crypto/null_encryption.rb +45 -0
 - data/lib/zip/crypto/traditional_encryption.rb +99 -0
 - data/lib/zip/decompressor.rb +2 -2
 - data/lib/zip/deflater.rb +11 -6
 - data/lib/zip/dos_time.rb +4 -5
 - data/lib/zip/entry.rb +159 -97
 - data/lib/zip/entry_set.rb +18 -18
 - data/lib/zip/errors.rb +15 -6
 - data/lib/zip/extra_field/generic.rb +8 -8
 - data/lib/zip/extra_field/ntfs.rb +90 -0
 - data/lib/zip/extra_field/old_unix.rb +44 -0
 - 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 +44 -6
 - data/lib/zip/extra_field/zip64_placeholder.rb +16 -0
 - data/lib/zip/extra_field.rb +20 -8
 - data/lib/zip/file.rb +126 -114
 - data/lib/zip/filesystem.rb +140 -139
 - data/lib/zip/inflater.rb +10 -9
 - data/lib/zip/input_stream.rb +105 -80
 - data/lib/zip/ioextras/abstract_input_stream.rb +15 -12
 - data/lib/zip/ioextras/abstract_output_stream.rb +0 -2
 - data/lib/zip/ioextras.rb +1 -3
 - data/lib/zip/null_compressor.rb +2 -2
 - data/lib/zip/null_decompressor.rb +4 -4
 - data/lib/zip/null_input_stream.rb +2 -1
 - data/lib/zip/output_stream.rb +57 -43
 - data/lib/zip/pass_thru_compressor.rb +4 -4
 - data/lib/zip/pass_thru_decompressor.rb +4 -5
 - data/lib/zip/streamable_directory.rb +2 -2
 - data/lib/zip/streamable_stream.rb +22 -13
 - data/lib/zip/version.rb +1 -1
 - data/lib/zip.rb +11 -2
 - data/samples/example.rb +30 -40
 - data/samples/example_filesystem.rb +16 -18
 - data/samples/example_recursive.rb +35 -27
 - data/samples/{gtkRubyzip.rb → gtk_ruby_zip.rb} +25 -27
 - data/samples/qtzip.rb +19 -28
 - data/samples/write_simple.rb +12 -13
 - data/samples/zipfind.rb +29 -37
 - data/test/basic_zip_file_test.rb +60 -0
 - data/test/case_sensitivity_test.rb +69 -0
 - data/test/central_directory_entry_test.rb +69 -0
 - data/test/central_directory_test.rb +100 -0
 - data/test/crypto/null_encryption_test.rb +53 -0
 - data/test/crypto/traditional_encryption_test.rb +80 -0
 - data/test/data/WarnInvalidDate.zip +0 -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/globTest/foo/bar/baz/foo.txt +0 -0
 - data/test/data/globTest/foo.txt +0 -0
 - data/test/data/globTest/food.txt +0 -0
 - data/test/data/globTest.zip +0 -0
 - data/test/data/mimetype +1 -0
 - data/test/data/notzippedruby.rb +7 -0
 - data/test/data/ntfs.zip +0 -0
 - data/test/data/oddExtraField.zip +0 -0
 - data/test/data/rubycode.zip +0 -0
 - data/test/data/rubycode2.zip +0 -0
 - data/test/data/test.xls +0 -0
 - data/test/data/testDirectory.bin +0 -0
 - data/test/data/zip64-sample.zip +0 -0
 - data/test/data/zipWithDirs.zip +0 -0
 - data/test/data/zipWithEncryption.zip +0 -0
 - data/test/deflater_test.rb +65 -0
 - data/test/encryption_test.rb +42 -0
 - data/test/entry_set_test.rb +152 -0
 - data/test/entry_test.rb +163 -0
 - data/test/errors_test.rb +34 -0
 - data/test/extra_field_test.rb +76 -0
 - data/test/file_extract_directory_test.rb +54 -0
 - data/test/file_extract_test.rb +83 -0
 - data/test/file_permissions_test.rb +69 -0
 - data/test/file_split_test.rb +57 -0
 - data/test/file_test.rb +563 -0
 - data/test/filesystem/dir_iterator_test.rb +58 -0
 - data/test/filesystem/directory_test.rb +121 -0
 - data/test/filesystem/file_mutating_test.rb +88 -0
 - data/test/filesystem/file_nonmutating_test.rb +508 -0
 - data/test/filesystem/file_stat_test.rb +64 -0
 - data/test/gentestfiles.rb +122 -0
 - data/test/inflater_test.rb +14 -0
 - data/test/input_stream_test.rb +182 -0
 - data/test/ioextras/abstract_input_stream_test.rb +102 -0
 - data/test/ioextras/abstract_output_stream_test.rb +106 -0
 - data/test/ioextras/fake_io_test.rb +18 -0
 - data/test/local_entry_test.rb +154 -0
 - data/test/output_stream_test.rb +128 -0
 - data/test/pass_thru_compressor_test.rb +30 -0
 - data/test/pass_thru_decompressor_test.rb +14 -0
 - data/test/samples/example_recursive_test.rb +37 -0
 - data/test/settings_test.rb +95 -0
 - data/test/test_helper.rb +221 -0
 - data/test/unicode_file_names_and_comments_test.rb +50 -0
 - data/test/zip64_full_test.rb +51 -0
 - data/test/zip64_support_test.rb +14 -0
 - metadata +198 -22
 - data/NEWS +0 -182
 
| 
         @@ -1,44 +1,53 @@ 
     | 
|
| 
       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 
     | 
    
         
            -
                   
     | 
| 
       6 
     | 
    
         
            -
             
     | 
| 
      
 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)
         
     | 
| 
      
 11 
     | 
    
         
            +
                  @temp_file.binmode
         
     | 
| 
       7 
12 
     | 
    
         
             
                end
         
     | 
| 
       8 
13 
     | 
    
         | 
| 
       9 
14 
     | 
    
         
             
                def get_output_stream
         
     | 
| 
       10 
15 
     | 
    
         
             
                  if block_given?
         
     | 
| 
       11 
16 
     | 
    
         
             
                    begin
         
     | 
| 
       12 
     | 
    
         
            -
                      yield(@ 
     | 
| 
      
 17 
     | 
    
         
            +
                      yield(@temp_file)
         
     | 
| 
       13 
18 
     | 
    
         
             
                    ensure
         
     | 
| 
       14 
     | 
    
         
            -
                      @ 
     | 
| 
      
 19 
     | 
    
         
            +
                      @temp_file.close
         
     | 
| 
       15 
20 
     | 
    
         
             
                    end
         
     | 
| 
       16 
21 
     | 
    
         
             
                  else
         
     | 
| 
       17 
     | 
    
         
            -
                    @ 
     | 
| 
      
 22 
     | 
    
         
            +
                    @temp_file
         
     | 
| 
       18 
23 
     | 
    
         
             
                  end
         
     | 
| 
       19 
24 
     | 
    
         
             
                end
         
     | 
| 
       20 
25 
     | 
    
         | 
| 
       21 
26 
     | 
    
         
             
                def get_input_stream
         
     | 
| 
       22 
     | 
    
         
            -
                   
     | 
| 
      
 27 
     | 
    
         
            +
                  unless @temp_file.closed?
         
     | 
| 
       23 
28 
     | 
    
         
             
                    raise StandardError, "cannot open entry for reading while its open for writing - #{name}"
         
     | 
| 
       24 
29 
     | 
    
         
             
                  end
         
     | 
| 
       25 
     | 
    
         
            -
                  @ 
     | 
| 
       26 
     | 
    
         
            -
                  @ 
     | 
| 
      
 30 
     | 
    
         
            +
                  @temp_file.open # reopens tempfile from top
         
     | 
| 
      
 31 
     | 
    
         
            +
                  @temp_file.binmode
         
     | 
| 
       27 
32 
     | 
    
         
             
                  if block_given?
         
     | 
| 
       28 
33 
     | 
    
         
             
                    begin
         
     | 
| 
       29 
     | 
    
         
            -
                      yield(@ 
     | 
| 
      
 34 
     | 
    
         
            +
                      yield(@temp_file)
         
     | 
| 
       30 
35 
     | 
    
         
             
                    ensure
         
     | 
| 
       31 
     | 
    
         
            -
                      @ 
     | 
| 
      
 36 
     | 
    
         
            +
                      @temp_file.close
         
     | 
| 
       32 
37 
     | 
    
         
             
                    end
         
     | 
| 
       33 
38 
     | 
    
         
             
                  else
         
     | 
| 
       34 
     | 
    
         
            -
                    @ 
     | 
| 
      
 39 
     | 
    
         
            +
                    @temp_file
         
     | 
| 
       35 
40 
     | 
    
         
             
                  end
         
     | 
| 
       36 
41 
     | 
    
         
             
                end
         
     | 
| 
       37 
     | 
    
         
            -
             
     | 
| 
      
 42 
     | 
    
         
            +
             
     | 
| 
       38 
43 
     | 
    
         
             
                def write_to_zip_output_stream(aZipOutputStream)
         
     | 
| 
       39 
44 
     | 
    
         
             
                  aZipOutputStream.put_next_entry(self)
         
     | 
| 
       40 
45 
     | 
    
         
             
                  get_input_stream { |is| ::Zip::IOExtras.copy_stream(aZipOutputStream, is) }
         
     | 
| 
       41 
46 
     | 
    
         
             
                end
         
     | 
| 
      
 47 
     | 
    
         
            +
             
     | 
| 
      
 48 
     | 
    
         
            +
                def clean_up
         
     | 
| 
      
 49 
     | 
    
         
            +
                  @temp_file.unlink
         
     | 
| 
      
 50 
     | 
    
         
            +
                end
         
     | 
| 
       42 
51 
     | 
    
         
             
              end
         
     | 
| 
       43 
52 
     | 
    
         
             
            end
         
     | 
| 
       44 
53 
     | 
    
         | 
    
        data/lib/zip/version.rb
    CHANGED
    
    
    
        data/lib/zip.rb
    CHANGED
    
    | 
         @@ -1,6 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            require 'delegate'
         
     | 
| 
       2 
2 
     | 
    
         
             
            require 'singleton'
         
     | 
| 
       3 
3 
     | 
    
         
             
            require 'tempfile'
         
     | 
| 
      
 4 
     | 
    
         
            +
            require 'tmpdir'
         
     | 
| 
       4 
5 
     | 
    
         
             
            require 'fileutils'
         
     | 
| 
       5 
6 
     | 
    
         
             
            require 'stringio'
         
     | 
| 
       6 
7 
     | 
    
         
             
            require 'zlib'
         
     | 
| 
         @@ -21,6 +22,9 @@ require 'zip/null_compressor' 
     | 
|
| 
       21 
22 
     | 
    
         
             
            require 'zip/null_input_stream'
         
     | 
| 
       22 
23 
     | 
    
         
             
            require 'zip/pass_thru_compressor'
         
     | 
| 
       23 
24 
     | 
    
         
             
            require 'zip/pass_thru_decompressor'
         
     | 
| 
      
 25 
     | 
    
         
            +
            require 'zip/crypto/encryption'
         
     | 
| 
      
 26 
     | 
    
         
            +
            require 'zip/crypto/null_encryption'
         
     | 
| 
      
 27 
     | 
    
         
            +
            require 'zip/crypto/traditional_encryption'
         
     | 
| 
       24 
28 
     | 
    
         
             
            require 'zip/inflater'
         
     | 
| 
       25 
29 
     | 
    
         
             
            require 'zip/deflater'
         
     | 
| 
       26 
30 
     | 
    
         
             
            require 'zip/streamable_stream'
         
     | 
| 
         @@ -30,13 +34,18 @@ require 'zip/errors' 
     | 
|
| 
       30 
34 
     | 
    
         | 
| 
       31 
35 
     | 
    
         
             
            module Zip
         
     | 
| 
       32 
36 
     | 
    
         
             
              extend self
         
     | 
| 
       33 
     | 
    
         
            -
              attr_accessor :unicode_names, :on_exists_proc, :continue_on_exists_proc
         
     | 
| 
      
 37 
     | 
    
         
            +
              attr_accessor :unicode_names, :on_exists_proc, :continue_on_exists_proc, :sort_entries, :default_compression, :write_zip64_support, :warn_invalid_date, :case_insensitive_match
         
     | 
| 
       34 
38 
     | 
    
         | 
| 
       35 
39 
     | 
    
         
             
              def reset!
         
     | 
| 
       36 
40 
     | 
    
         
             
                @_ran_once = false
         
     | 
| 
       37 
41 
     | 
    
         
             
                @unicode_names = false
         
     | 
| 
       38 
42 
     | 
    
         
             
                @on_exists_proc = false
         
     | 
| 
       39 
43 
     | 
    
         
             
                @continue_on_exists_proc = false
         
     | 
| 
      
 44 
     | 
    
         
            +
                @sort_entries = false
         
     | 
| 
      
 45 
     | 
    
         
            +
                @default_compression = ::Zlib::DEFAULT_COMPRESSION
         
     | 
| 
      
 46 
     | 
    
         
            +
                @write_zip64_support = false
         
     | 
| 
      
 47 
     | 
    
         
            +
                @warn_invalid_date = true
         
     | 
| 
      
 48 
     | 
    
         
            +
                @case_insensitive_match = false
         
     | 
| 
       40 
49 
     | 
    
         
             
              end
         
     | 
| 
       41 
50 
     | 
    
         | 
| 
       42 
51 
     | 
    
         
             
              def setup
         
     | 
| 
         @@ -49,4 +58,4 @@ end 
     | 
|
| 
       49 
58 
     | 
    
         | 
| 
       50 
59 
     | 
    
         
             
            # Copyright (C) 2002, 2003 Thomas Sondergaard
         
     | 
| 
       51 
60 
     | 
    
         
             
            # rubyzip is free software; you can redistribute it and/or
         
     | 
| 
       52 
     | 
    
         
            -
            # modify it under the terms of the ruby license.
         
     | 
| 
      
 61 
     | 
    
         
            +
            # modify it under the terms of the ruby license.
         
     | 
    
        data/samples/example.rb
    CHANGED
    
    | 
         @@ -1,89 +1,79 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            #!/usr/bin/env ruby
         
     | 
| 
       2 
2 
     | 
    
         | 
| 
       3 
     | 
    
         
            -
            $: <<  
     | 
| 
       4 
     | 
    
         
            -
            system( 
     | 
| 
      
 3 
     | 
    
         
            +
            $: << '../lib'
         
     | 
| 
      
 4 
     | 
    
         
            +
            system('zip example.zip example.rb gtk_ruby_zip.rb')
         
     | 
| 
       5 
5 
     | 
    
         | 
| 
       6 
     | 
    
         
            -
            require 'zip 
     | 
| 
      
 6 
     | 
    
         
            +
            require 'zip'
         
     | 
| 
       7 
7 
     | 
    
         | 
| 
       8 
8 
     | 
    
         
             
            ####### Using ZipInputStream alone: #######
         
     | 
| 
       9 
9 
     | 
    
         | 
| 
       10 
     | 
    
         
            -
            Zip::InputStream.open( 
     | 
| 
       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( 
     | 
| 
       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( 
     | 
| 
       37 
     | 
    
         
            -
               
     | 
| 
       38 
     | 
    
         
            -
              zos. 
     | 
| 
       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( 
     | 
| 
       42 
     | 
    
         
            -
              zos.puts  
     | 
| 
      
 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( 
     | 
| 
       51 
     | 
    
         
            -
               
     | 
| 
       52 
     | 
    
         
            -
               
     | 
| 
       53 
     | 
    
         
            -
               
     | 
| 
       54 
     | 
    
         
            -
             
     | 
| 
       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( 
     | 
| 
       59 
     | 
    
         
            -
               
     | 
| 
       60 
     | 
    
         
            -
               
     | 
| 
       61 
     | 
    
         
            -
               
     | 
| 
       62 
     | 
    
         
            -
             
     | 
| 
       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( 
     | 
| 
       69 
     | 
    
         
            -
              puts  
     | 
| 
      
 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  
     | 
| 
      
 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( 
     | 
| 
      
 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( 
     | 
| 
       82 
     | 
    
         
            -
               
     | 
| 
       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.to_f * 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 
     | 
    
         
            -
            $: <<  
     | 
| 
      
 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 
     | 
    
         | 
| 
         @@ -1,4 +1,4 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            require 'zip 
     | 
| 
      
 1 
     | 
    
         
            +
            require 'zip'
         
     | 
| 
       2 
2 
     | 
    
         | 
| 
       3 
3 
     | 
    
         
             
            # This is a simple example which uses rubyzip to
         
     | 
| 
       4 
4 
     | 
    
         
             
            # recursively generate a zip file from the contents of
         
     | 
| 
         @@ -7,43 +7,51 @@ require 'zip/zip' 
     | 
|
| 
       7 
7 
     | 
    
         
             
            #
         
     | 
| 
       8 
8 
     | 
    
         
             
            # Usage:
         
     | 
| 
       9 
9 
     | 
    
         
             
            #   directoryToZip = "/tmp/input"
         
     | 
| 
       10 
     | 
    
         
            -
            #    
     | 
| 
       11 
     | 
    
         
            -
            #   zf = ZipFileGenerator.new( 
     | 
| 
      
 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 
     | 
    
         
            -
                
         
     | 
| 
       48 
     | 
    
         
            -
            end
         
     | 
| 
       49 
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
         
     | 
| 
      
 57 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -1,17 +1,17 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            #!/usr/bin/env ruby
         
     | 
| 
       2 
2 
     | 
    
         | 
| 
       3 
     | 
    
         
            -
            $: <<  
     | 
| 
      
 3 
     | 
    
         
            +
            $: << '../lib'
         
     | 
| 
       4 
4 
     | 
    
         | 
| 
       5 
5 
     | 
    
         
             
            $VERBOSE = true
         
     | 
| 
       6 
6 
     | 
    
         | 
| 
       7 
7 
     | 
    
         
             
            require 'gtk'
         
     | 
| 
       8 
     | 
    
         
            -
            require 'zip 
     | 
| 
      
 8 
     | 
    
         
            +
            require 'zip'
         
     | 
| 
       9 
9 
     | 
    
         | 
| 
       10 
10 
     | 
    
         
             
            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 
     | 
    
         
            -
            require 'zip 
     | 
| 
       11 
     | 
    
         
            -
             
     | 
| 
       12 
     | 
    
         
            -
             
     | 
| 
      
 10 
     | 
    
         
            +
            require 'zip'
         
     | 
| 
       13 
11 
     | 
    
         | 
| 
       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()'))
         
     | 
| 
         @@ -31,17 +27,15 @@ class ZipDialog < ZipDialogUI 
     | 
|
| 
       31 
27 
     | 
    
         
             
              def each(&proc)
         
     | 
| 
       32 
28 
     | 
    
         
             
                Zip::File.foreach(@zip_filename, &proc)
         
     | 
| 
       33 
29 
     | 
    
         
             
              end
         
     | 
| 
       34 
     | 
    
         
            -
             
     | 
| 
       35 
     | 
    
         
            -
              def refresh 
     | 
| 
       36 
     | 
    
         
            -
                lv = child( 
     | 
| 
      
 30 
     | 
    
         
            +
             
     | 
| 
      
 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
         
     |