rubyzip 1.2.0 → 2.3.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.
- checksums.yaml +5 -5
- data/README.md +89 -43
- data/Rakefile +3 -0
- data/lib/zip.rb +14 -3
- data/lib/zip/central_directory.rb +12 -8
- data/lib/zip/compressor.rb +1 -2
- data/lib/zip/constants.rb +55 -3
- data/lib/zip/crypto/decrypted_io.rb +40 -0
- data/lib/zip/crypto/null_encryption.rb +2 -4
- data/lib/zip/crypto/traditional_encryption.rb +9 -9
- data/lib/zip/decompressor.rb +20 -2
- data/lib/zip/dos_time.rb +13 -8
- data/lib/zip/entry.rb +115 -80
- data/lib/zip/entry_set.rb +6 -4
- data/lib/zip/errors.rb +2 -0
- data/lib/zip/extra_field.rb +12 -10
- data/lib/zip/extra_field/generic.rb +10 -9
- data/lib/zip/extra_field/ntfs.rb +4 -0
- data/lib/zip/extra_field/old_unix.rb +3 -1
- data/lib/zip/extra_field/universal_time.rb +42 -12
- data/lib/zip/extra_field/unix.rb +3 -1
- data/lib/zip/extra_field/zip64.rb +4 -2
- data/lib/zip/extra_field/zip64_placeholder.rb +1 -2
- data/lib/zip/file.rb +136 -100
- data/lib/zip/filesystem.rb +199 -179
- data/lib/zip/inflater.rb +24 -36
- data/lib/zip/input_stream.rb +37 -27
- data/lib/zip/ioextras.rb +1 -1
- data/lib/zip/ioextras/abstract_input_stream.rb +20 -9
- data/lib/zip/ioextras/abstract_output_stream.rb +4 -4
- data/lib/zip/null_decompressor.rb +1 -9
- data/lib/zip/output_stream.rb +19 -10
- data/lib/zip/pass_thru_compressor.rb +2 -2
- data/lib/zip/pass_thru_decompressor.rb +14 -23
- data/lib/zip/streamable_directory.rb +3 -3
- data/lib/zip/streamable_stream.rb +6 -10
- data/lib/zip/version.rb +1 -1
- data/samples/example.rb +2 -2
- data/samples/example_filesystem.rb +1 -1
- data/samples/example_recursive.rb +15 -18
- data/samples/gtk_ruby_zip.rb +20 -20
- data/samples/qtzip.rb +7 -7
- data/samples/write_simple.rb +2 -4
- data/samples/zipfind.rb +23 -22
- metadata +41 -130
- data/test/basic_zip_file_test.rb +0 -60
- data/test/case_sensitivity_test.rb +0 -69
- data/test/central_directory_entry_test.rb +0 -69
- data/test/central_directory_test.rb +0 -100
- data/test/crypto/null_encryption_test.rb +0 -53
- data/test/crypto/traditional_encryption_test.rb +0 -80
- data/test/data/WarnInvalidDate.zip +0 -0
- data/test/data/file1.txt +0 -46
- data/test/data/file1.txt.deflatedData +0 -0
- data/test/data/file2.txt +0 -1504
- data/test/data/globTest.zip +0 -0
- data/test/data/globTest/foo.txt +0 -0
- data/test/data/globTest/foo/bar/baz/foo.txt +0 -0
- data/test/data/globTest/food.txt +0 -0
- data/test/data/mimetype +0 -1
- data/test/data/notzippedruby.rb +0 -7
- 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 +0 -65
- data/test/encryption_test.rb +0 -42
- data/test/entry_set_test.rb +0 -152
- data/test/entry_test.rb +0 -163
- data/test/errors_test.rb +0 -34
- data/test/extra_field_test.rb +0 -76
- data/test/file_extract_directory_test.rb +0 -54
- data/test/file_extract_test.rb +0 -83
- data/test/file_permissions_test.rb +0 -69
- data/test/file_split_test.rb +0 -57
- data/test/file_test.rb +0 -563
- data/test/filesystem/dir_iterator_test.rb +0 -58
- data/test/filesystem/directory_test.rb +0 -121
- data/test/filesystem/file_mutating_test.rb +0 -88
- data/test/filesystem/file_nonmutating_test.rb +0 -508
- data/test/filesystem/file_stat_test.rb +0 -64
- data/test/gentestfiles.rb +0 -122
- data/test/inflater_test.rb +0 -14
- data/test/input_stream_test.rb +0 -182
- data/test/ioextras/abstract_input_stream_test.rb +0 -102
- data/test/ioextras/abstract_output_stream_test.rb +0 -106
- data/test/ioextras/fake_io_test.rb +0 -18
- data/test/local_entry_test.rb +0 -154
- data/test/output_stream_test.rb +0 -128
- data/test/pass_thru_compressor_test.rb +0 -30
- data/test/pass_thru_decompressor_test.rb +0 -14
- data/test/samples/example_recursive_test.rb +0 -37
- data/test/settings_test.rb +0 -95
- data/test/test_helper.rb +0 -221
- data/test/unicode_file_names_and_comments_test.rb +0 -50
- data/test/zip64_full_test.rb +0 -51
- data/test/zip64_support_test.rb +0 -14
    
        data/lib/zip/inflater.rb
    CHANGED
    
    | @@ -1,64 +1,52 @@ | |
| 1 1 | 
             
            module Zip
         | 
| 2 2 | 
             
              class Inflater < Decompressor #:nodoc:all
         | 
| 3 | 
            -
                def initialize( | 
| 4 | 
            -
                  super | 
| 5 | 
            -
                  @zlib_inflater           = ::Zlib::Inflate.new(-Zlib::MAX_WBITS)
         | 
| 6 | 
            -
                  @output_buffer           = ''
         | 
| 7 | 
            -
                  @has_returned_empty_string = false
         | 
| 8 | 
            -
                  @decrypter               = decrypter
         | 
| 9 | 
            -
                end
         | 
| 3 | 
            +
                def initialize(*args)
         | 
| 4 | 
            +
                  super
         | 
| 10 5 |  | 
| 11 | 
            -
             | 
| 12 | 
            -
                   | 
| 13 | 
            -
                  while readEverything || @output_buffer.bytesize < number_of_bytes
         | 
| 14 | 
            -
                    break if internal_input_finished?
         | 
| 15 | 
            -
                    @output_buffer << internal_produce_input(buf)
         | 
| 16 | 
            -
                  end
         | 
| 17 | 
            -
                  return value_when_finished if @output_buffer.bytesize == 0 && input_finished?
         | 
| 18 | 
            -
                  end_index = number_of_bytes.nil? ? @output_buffer.bytesize : number_of_bytes
         | 
| 19 | 
            -
                  @output_buffer.slice!(0...end_index)
         | 
| 6 | 
            +
                  @buffer = +''
         | 
| 7 | 
            +
                  @zlib_inflater = ::Zlib::Inflate.new(-Zlib::MAX_WBITS)
         | 
| 20 8 | 
             
                end
         | 
| 21 9 |  | 
| 22 | 
            -
                def  | 
| 23 | 
            -
                   | 
| 24 | 
            -
             | 
| 25 | 
            -
                   | 
| 26 | 
            -
                     | 
| 10 | 
            +
                def read(length = nil, outbuf = '')
         | 
| 11 | 
            +
                  return (length.nil? || length.zero? ? '' : nil) if eof
         | 
| 12 | 
            +
             | 
| 13 | 
            +
                  while length.nil? || (@buffer.bytesize < length)
         | 
| 14 | 
            +
                    break if input_finished?
         | 
| 15 | 
            +
             | 
| 16 | 
            +
                    @buffer << produce_input
         | 
| 27 17 | 
             
                  end
         | 
| 18 | 
            +
             | 
| 19 | 
            +
                  outbuf.replace(@buffer.slice!(0...(length || @buffer.bytesize)))
         | 
| 28 20 | 
             
                end
         | 
| 29 21 |  | 
| 30 | 
            -
                 | 
| 31 | 
            -
             | 
| 32 | 
            -
                def input_finished?
         | 
| 33 | 
            -
                  @output_buffer.empty? && internal_input_finished?
         | 
| 22 | 
            +
                def eof
         | 
| 23 | 
            +
                  @buffer.empty? && input_finished?
         | 
| 34 24 | 
             
                end
         | 
| 35 25 |  | 
| 36 | 
            -
                alias  | 
| 37 | 
            -
                alias :eof? input_finished?
         | 
| 26 | 
            +
                alias eof? eof
         | 
| 38 27 |  | 
| 39 28 | 
             
                private
         | 
| 40 29 |  | 
| 41 | 
            -
                def  | 
| 30 | 
            +
                def produce_input
         | 
| 42 31 | 
             
                  retried = 0
         | 
| 43 32 | 
             
                  begin
         | 
| 44 | 
            -
                    @zlib_inflater.inflate( | 
| 33 | 
            +
                    @zlib_inflater.inflate(input_stream.read(Decompressor::CHUNK_SIZE))
         | 
| 45 34 | 
             
                  rescue Zlib::BufError
         | 
| 46 35 | 
             
                    raise if retried >= 5 # how many times should we retry?
         | 
| 36 | 
            +
             | 
| 47 37 | 
             
                    retried += 1
         | 
| 48 38 | 
             
                    retry
         | 
| 49 39 | 
             
                  end
         | 
| 40 | 
            +
                rescue Zlib::Error
         | 
| 41 | 
            +
                  raise(::Zip::DecompressionError, 'zlib error while inflating')
         | 
| 50 42 | 
             
                end
         | 
| 51 43 |  | 
| 52 | 
            -
                def  | 
| 44 | 
            +
                def input_finished?
         | 
| 53 45 | 
             
                  @zlib_inflater.finished?
         | 
| 54 46 | 
             
                end
         | 
| 55 | 
            -
             | 
| 56 | 
            -
                def value_when_finished # mimic behaviour of ruby File object.
         | 
| 57 | 
            -
                  return if @has_returned_empty_string
         | 
| 58 | 
            -
                  @has_returned_empty_string = true
         | 
| 59 | 
            -
                  ''
         | 
| 60 | 
            -
                end
         | 
| 61 47 | 
             
              end
         | 
| 48 | 
            +
             | 
| 49 | 
            +
              ::Zip::Decompressor.register(::Zip::COMPRESSION_METHOD_DEFLATE, ::Zip::Inflater)
         | 
| 62 50 | 
             
            end
         | 
| 63 51 |  | 
| 64 52 | 
             
            # Copyright (C) 2002, 2003 Thomas Sondergaard
         | 
    
        data/lib/zip/input_stream.rb
    CHANGED
    
    | @@ -39,6 +39,8 @@ module Zip | |
| 39 39 | 
             
              # class.
         | 
| 40 40 |  | 
| 41 41 | 
             
              class InputStream
         | 
| 42 | 
            +
                CHUNK_SIZE = 32_768
         | 
| 43 | 
            +
             | 
| 42 44 | 
             
                include ::Zip::IOExtras::AbstractInputStream
         | 
| 43 45 |  | 
| 44 46 | 
             
                # Opens the indicated zip file. An exception is thrown
         | 
| @@ -49,7 +51,7 @@ module Zip | |
| 49 51 | 
             
                # @param offset [Integer] offset in the IO/StringIO
         | 
| 50 52 | 
             
                def initialize(context, offset = 0, decrypter = nil)
         | 
| 51 53 | 
             
                  super()
         | 
| 52 | 
            -
                  @archive_io | 
| 54 | 
            +
                  @archive_io    = get_io(context, offset)
         | 
| 53 55 | 
             
                  @decompressor  = ::Zip::NullDecompressor
         | 
| 54 56 | 
             
                  @decrypter     = decrypter || ::Zip::NullDecrypter.new
         | 
| 55 57 | 
             
                  @current_entry = nil
         | 
| @@ -71,6 +73,7 @@ module Zip | |
| 71 73 | 
             
                # Rewinds the stream to the beginning of the current entry
         | 
| 72 74 | 
             
                def rewind
         | 
| 73 75 | 
             
                  return if @current_entry.nil?
         | 
| 76 | 
            +
             | 
| 74 77 | 
             
                  @lineno = 0
         | 
| 75 78 | 
             
                  @pos    = 0
         | 
| 76 79 | 
             
                  @archive_io.seek(@current_entry.local_header_offset, IO::SEEK_SET)
         | 
| @@ -78,16 +81,10 @@ module Zip | |
| 78 81 | 
             
                end
         | 
| 79 82 |  | 
| 80 83 | 
             
                # Modeled after IO.sysread
         | 
| 81 | 
            -
                def sysread( | 
| 82 | 
            -
                  @decompressor. | 
| 83 | 
            -
                end
         | 
| 84 | 
            -
             | 
| 85 | 
            -
                def eof
         | 
| 86 | 
            -
                  @output_buffer.empty? && @decompressor.eof
         | 
| 84 | 
            +
                def sysread(length = nil, outbuf = '')
         | 
| 85 | 
            +
                  @decompressor.read(length, outbuf)
         | 
| 87 86 | 
             
                end
         | 
| 88 87 |  | 
| 89 | 
            -
                alias :eof? eof
         | 
| 90 | 
            -
             | 
| 91 88 | 
             
                class << self
         | 
| 92 89 | 
             
                  # Same as #initialize but if a block is passed the opened
         | 
| 93 90 | 
             
                  # stream is passed to the block and closed when the block
         | 
| @@ -95,6 +92,7 @@ module Zip | |
| 95 92 | 
             
                  def open(filename_or_io, offset = 0, decrypter = nil)
         | 
| 96 93 | 
             
                    zio = new(filename_or_io, offset, decrypter)
         | 
| 97 94 | 
             
                    return zio unless block_given?
         | 
| 95 | 
            +
             | 
| 98 96 | 
             
                    begin
         | 
| 99 97 | 
             
                      yield zio
         | 
| 100 98 | 
             
                    ensure
         | 
| @@ -103,8 +101,8 @@ module Zip | |
| 103 101 | 
             
                  end
         | 
| 104 102 |  | 
| 105 103 | 
             
                  def open_buffer(filename_or_io, offset = 0)
         | 
| 106 | 
            -
                     | 
| 107 | 
            -
                    open(filename_or_io, offset)
         | 
| 104 | 
            +
                    warn 'open_buffer is deprecated!!! Use open instead!'
         | 
| 105 | 
            +
                    ::Zip::InputStream.open(filename_or_io, offset)
         | 
| 108 106 | 
             
                  end
         | 
| 109 107 | 
             
                end
         | 
| 110 108 |  | 
| @@ -124,43 +122,55 @@ module Zip | |
| 124 122 |  | 
| 125 123 | 
             
                def open_entry
         | 
| 126 124 | 
             
                  @current_entry = ::Zip::Entry.read_local_entry(@archive_io)
         | 
| 127 | 
            -
                  if @current_entry && @current_entry. | 
| 125 | 
            +
                  if @current_entry && @current_entry.encrypted? && @decrypter.kind_of?(NullEncrypter)
         | 
| 128 126 | 
             
                    raise Error, 'password required to decode zip file'
         | 
| 129 127 | 
             
                  end
         | 
| 130 | 
            -
             | 
| 128 | 
            +
             | 
| 129 | 
            +
                  if @current_entry && @current_entry.incomplete? && @current_entry.crc == 0 \
         | 
| 131 130 | 
             
                    && @current_entry.compressed_size == 0 \
         | 
| 132 | 
            -
                    && @current_entry.size == 0 && !@ | 
| 131 | 
            +
                    && @current_entry.size == 0 && !@complete_entry
         | 
| 133 132 | 
             
                    raise GPFBit3Error,
         | 
| 134 133 | 
             
                          'General purpose flag Bit 3 is set so not possible to get proper info from local header.' \
         | 
| 135 134 | 
             
                          'Please use ::Zip::File instead of ::Zip::InputStream'
         | 
| 136 135 | 
             
                  end
         | 
| 137 | 
            -
                  @ | 
| 136 | 
            +
                  @decrypted_io = get_decrypted_io
         | 
| 137 | 
            +
                  @decompressor = get_decompressor
         | 
| 138 138 | 
             
                  flush
         | 
| 139 139 | 
             
                  @current_entry
         | 
| 140 140 | 
             
                end
         | 
| 141 141 |  | 
| 142 | 
            +
                def get_decrypted_io
         | 
| 143 | 
            +
                  header = @archive_io.read(@decrypter.header_bytesize)
         | 
| 144 | 
            +
                  @decrypter.reset!(header)
         | 
| 145 | 
            +
             | 
| 146 | 
            +
                  ::Zip::DecryptedIo.new(@archive_io, @decrypter)
         | 
| 147 | 
            +
                end
         | 
| 148 | 
            +
             | 
| 142 149 | 
             
                def get_decompressor
         | 
| 143 | 
            -
                   | 
| 144 | 
            -
             | 
| 145 | 
            -
             | 
| 146 | 
            -
             | 
| 147 | 
            -
             | 
| 148 | 
            -
             | 
| 149 | 
            -
             | 
| 150 | 
            -
                     | 
| 151 | 
            -
             | 
| 152 | 
            -
                   | 
| 150 | 
            +
                  return ::Zip::NullDecompressor if @current_entry.nil?
         | 
| 151 | 
            +
             | 
| 152 | 
            +
                  decompressed_size =
         | 
| 153 | 
            +
                    if @current_entry.incomplete? && @current_entry.crc == 0 && @current_entry.size == 0 && @complete_entry
         | 
| 154 | 
            +
                      @complete_entry.size
         | 
| 155 | 
            +
                    else
         | 
| 156 | 
            +
                      @current_entry.size
         | 
| 157 | 
            +
                    end
         | 
| 158 | 
            +
             | 
| 159 | 
            +
                  decompressor_class = ::Zip::Decompressor.find_by_compression_method(@current_entry.compression_method)
         | 
| 160 | 
            +
                  if decompressor_class.nil?
         | 
| 153 161 | 
             
                    raise ::Zip::CompressionMethodError,
         | 
| 154 162 | 
             
                          "Unsupported compression method #{@current_entry.compression_method}"
         | 
| 155 163 | 
             
                  end
         | 
| 164 | 
            +
             | 
| 165 | 
            +
                  decompressor_class.new(@decrypted_io, decompressed_size)
         | 
| 156 166 | 
             
                end
         | 
| 157 167 |  | 
| 158 168 | 
             
                def produce_input
         | 
| 159 | 
            -
                  @decompressor. | 
| 169 | 
            +
                  @decompressor.read(CHUNK_SIZE)
         | 
| 160 170 | 
             
                end
         | 
| 161 171 |  | 
| 162 172 | 
             
                def input_finished?
         | 
| 163 | 
            -
                  @decompressor. | 
| 173 | 
            +
                  @decompressor.eof
         | 
| 164 174 | 
             
                end
         | 
| 165 175 | 
             
              end
         | 
| 166 176 | 
             
            end
         | 
    
        data/lib/zip/ioextras.rb
    CHANGED
    
    
| @@ -33,8 +33,9 @@ module Zip | |
| 33 33 | 
             
                             sysread(number_of_bytes, buf)
         | 
| 34 34 | 
             
                           end
         | 
| 35 35 |  | 
| 36 | 
            -
                    if tbuf.nil? || tbuf. | 
| 36 | 
            +
                    if tbuf.nil? || tbuf.empty?
         | 
| 37 37 | 
             
                      return nil if number_of_bytes
         | 
| 38 | 
            +
             | 
| 38 39 | 
             
                      return ''
         | 
| 39 40 | 
             
                    end
         | 
| 40 41 |  | 
| @@ -48,13 +49,13 @@ module Zip | |
| 48 49 | 
             
                    buf
         | 
| 49 50 | 
             
                  end
         | 
| 50 51 |  | 
| 51 | 
            -
                  def readlines(a_sep_string =  | 
| 52 | 
            +
                  def readlines(a_sep_string = $INPUT_RECORD_SEPARATOR)
         | 
| 52 53 | 
             
                    ret_val = []
         | 
| 53 54 | 
             
                    each_line(a_sep_string) { |line| ret_val << line }
         | 
| 54 55 | 
             
                    ret_val
         | 
| 55 56 | 
             
                  end
         | 
| 56 57 |  | 
| 57 | 
            -
                  def gets(a_sep_string =  | 
| 58 | 
            +
                  def gets(a_sep_string = $INPUT_RECORD_SEPARATOR, number_of_bytes = nil)
         | 
| 58 59 | 
             
                    @lineno = @lineno.next
         | 
| 59 60 |  | 
| 60 61 | 
             
                    if number_of_bytes.respond_to?(:to_int)
         | 
| @@ -62,20 +63,22 @@ module Zip | |
| 62 63 | 
             
                      a_sep_string = a_sep_string.to_str if a_sep_string
         | 
| 63 64 | 
             
                    elsif a_sep_string.respond_to?(:to_int)
         | 
| 64 65 | 
             
                      number_of_bytes = a_sep_string.to_int
         | 
| 65 | 
            -
                      a_sep_string    =  | 
| 66 | 
            +
                      a_sep_string    = $INPUT_RECORD_SEPARATOR
         | 
| 66 67 | 
             
                    else
         | 
| 67 68 | 
             
                      number_of_bytes = nil
         | 
| 68 69 | 
             
                      a_sep_string = a_sep_string.to_str if a_sep_string
         | 
| 69 70 | 
             
                    end
         | 
| 70 71 |  | 
| 71 72 | 
             
                    return read(number_of_bytes) if a_sep_string.nil?
         | 
| 72 | 
            -
             | 
| 73 | 
            +
             | 
| 74 | 
            +
                    a_sep_string = "#{$INPUT_RECORD_SEPARATOR}#{$INPUT_RECORD_SEPARATOR}" if a_sep_string.empty?
         | 
| 73 75 |  | 
| 74 76 | 
             
                    buffer_index = 0
         | 
| 75 77 | 
             
                    over_limit   = (number_of_bytes && @output_buffer.bytesize >= number_of_bytes)
         | 
| 76 78 | 
             
                    while (match_index = @output_buffer.index(a_sep_string, buffer_index)).nil? && !over_limit
         | 
| 77 79 | 
             
                      buffer_index = [buffer_index, @output_buffer.bytesize - a_sep_string.bytesize].max
         | 
| 78 80 | 
             
                      return @output_buffer.empty? ? nil : flush if input_finished?
         | 
| 81 | 
            +
             | 
| 79 82 | 
             
                      @output_buffer << produce_input
         | 
| 80 83 | 
             
                      over_limit = (number_of_bytes && @output_buffer.bytesize >= number_of_bytes)
         | 
| 81 84 | 
             
                    end
         | 
| @@ -94,18 +97,26 @@ module Zip | |
| 94 97 | 
             
                    ret_val
         | 
| 95 98 | 
             
                  end
         | 
| 96 99 |  | 
| 97 | 
            -
                  def readline(a_sep_string =  | 
| 100 | 
            +
                  def readline(a_sep_string = $INPUT_RECORD_SEPARATOR)
         | 
| 98 101 | 
             
                    ret_val = gets(a_sep_string)
         | 
| 99 102 | 
             
                    raise EOFError unless ret_val
         | 
| 103 | 
            +
             | 
| 100 104 | 
             
                    ret_val
         | 
| 101 105 | 
             
                  end
         | 
| 102 106 |  | 
| 103 | 
            -
                  def each_line(a_sep_string =  | 
| 104 | 
            -
                    yield readline(a_sep_string)  | 
| 107 | 
            +
                  def each_line(a_sep_string = $INPUT_RECORD_SEPARATOR)
         | 
| 108 | 
            +
                    loop { yield readline(a_sep_string) }
         | 
| 105 109 | 
             
                  rescue EOFError
         | 
| 110 | 
            +
                    # We just need to catch this; we don't need to handle it.
         | 
| 111 | 
            +
                  end
         | 
| 112 | 
            +
             | 
| 113 | 
            +
                  alias each each_line
         | 
| 114 | 
            +
             | 
| 115 | 
            +
                  def eof
         | 
| 116 | 
            +
                    @output_buffer.empty? && input_finished?
         | 
| 106 117 | 
             
                  end
         | 
| 107 118 |  | 
| 108 | 
            -
                   | 
| 119 | 
            +
                  alias eof? eof
         | 
| 109 120 | 
             
                end
         | 
| 110 121 | 
             
              end
         | 
| 111 122 | 
             
            end
         | 
| @@ -11,21 +11,21 @@ module Zip | |
| 11 11 | 
             
                  end
         | 
| 12 12 |  | 
| 13 13 | 
             
                  def print(*params)
         | 
| 14 | 
            -
                    self << params.join( | 
| 14 | 
            +
                    self << params.join($OUTPUT_FIELD_SEPARATOR) << $OUTPUT_RECORD_SEPARATOR.to_s
         | 
| 15 15 | 
             
                  end
         | 
| 16 16 |  | 
| 17 17 | 
             
                  def printf(a_format_string, *params)
         | 
| 18 | 
            -
                    self <<  | 
| 18 | 
            +
                    self << format(a_format_string, *params)
         | 
| 19 19 | 
             
                  end
         | 
| 20 20 |  | 
| 21 21 | 
             
                  def putc(an_object)
         | 
| 22 22 | 
             
                    self << case an_object
         | 
| 23 | 
            -
                            when  | 
| 23 | 
            +
                            when Integer
         | 
| 24 24 | 
             
                              an_object.chr
         | 
| 25 25 | 
             
                            when String
         | 
| 26 26 | 
             
                              an_object
         | 
| 27 27 | 
             
                            else
         | 
| 28 | 
            -
                              raise TypeError, 'putc: Only  | 
| 28 | 
            +
                              raise TypeError, 'putc: Only Integer and String supported'
         | 
| 29 29 | 
             
                            end
         | 
| 30 30 | 
             
                    an_object
         | 
| 31 31 | 
             
                  end
         | 
| @@ -2,18 +2,10 @@ module Zip | |
| 2 2 | 
             
              module NullDecompressor #:nodoc:all
         | 
| 3 3 | 
             
                module_function
         | 
| 4 4 |  | 
| 5 | 
            -
                def  | 
| 5 | 
            +
                def read(_length = nil, _outbuf = nil)
         | 
| 6 6 | 
             
                  nil
         | 
| 7 7 | 
             
                end
         | 
| 8 8 |  | 
| 9 | 
            -
                def produce_input
         | 
| 10 | 
            -
                  nil
         | 
| 11 | 
            -
                end
         | 
| 12 | 
            -
             | 
| 13 | 
            -
                def input_finished?
         | 
| 14 | 
            -
                  true
         | 
| 15 | 
            -
                end
         | 
| 16 | 
            -
             | 
| 17 9 | 
             
                def eof
         | 
| 18 10 | 
             
                  true
         | 
| 19 11 | 
             
                end
         | 
    
        data/lib/zip/output_stream.rb
    CHANGED
    
    | @@ -49,6 +49,7 @@ module Zip | |
| 49 49 | 
             
                class << self
         | 
| 50 50 | 
             
                  def open(file_name, encrypter = nil)
         | 
| 51 51 | 
             
                    return new(file_name) unless block_given?
         | 
| 52 | 
            +
             | 
| 52 53 | 
             
                    zos = new(file_name, false, encrypter)
         | 
| 53 54 | 
             
                    yield zos
         | 
| 54 55 | 
             
                  ensure
         | 
| @@ -57,6 +58,7 @@ module Zip | |
| 57 58 |  | 
| 58 59 | 
             
                  # Same as #open but writes to a filestream instead
         | 
| 59 60 | 
             
                  def write_buffer(io = ::StringIO.new(''), encrypter = nil)
         | 
| 61 | 
            +
                    io.binmode if io.respond_to?(:binmode)
         | 
| 60 62 | 
             
                    zos = new(io, true, encrypter)
         | 
| 61 63 | 
             
                    yield zos
         | 
| 62 64 | 
             
                    zos.close_buffer
         | 
| @@ -66,6 +68,7 @@ module Zip | |
| 66 68 | 
             
                # Closes the stream and writes the central directory to the zip file
         | 
| 67 69 | 
             
                def close
         | 
| 68 70 | 
             
                  return if @closed
         | 
| 71 | 
            +
             | 
| 69 72 | 
             
                  finalize_current_entry
         | 
| 70 73 | 
             
                  update_local_headers
         | 
| 71 74 | 
             
                  write_central_directory
         | 
| @@ -76,6 +79,7 @@ module Zip | |
| 76 79 | 
             
                # Closes the stream and writes the central directory to the zip file
         | 
| 77 80 | 
             
                def close_buffer
         | 
| 78 81 | 
             
                  return @output_stream if @closed
         | 
| 82 | 
            +
             | 
| 79 83 | 
             
                  finalize_current_entry
         | 
| 80 84 | 
             
                  update_local_headers
         | 
| 81 85 | 
             
                  write_central_directory
         | 
| @@ -87,14 +91,15 @@ module Zip | |
| 87 91 | 
             
                # +entry+ can be a ZipEntry object or a string.
         | 
| 88 92 | 
             
                def put_next_entry(entry_name, comment = nil, extra = nil, compression_method = Entry::DEFLATED, level = Zip.default_compression)
         | 
| 89 93 | 
             
                  raise Error, 'zip stream is closed' if @closed
         | 
| 90 | 
            -
             | 
| 91 | 
            -
             | 
| 92 | 
            -
             | 
| 93 | 
            -
             | 
| 94 | 
            -
             | 
| 94 | 
            +
             | 
| 95 | 
            +
                  new_entry = if entry_name.kind_of?(Entry)
         | 
| 96 | 
            +
                                entry_name
         | 
| 97 | 
            +
                              else
         | 
| 98 | 
            +
                                Entry.new(@file_name, entry_name.to_s)
         | 
| 99 | 
            +
                              end
         | 
| 95 100 | 
             
                  new_entry.comment = comment unless comment.nil?
         | 
| 96 101 | 
             
                  unless extra.nil?
         | 
| 97 | 
            -
                    new_entry.extra = extra. | 
| 102 | 
            +
                    new_entry.extra = extra.kind_of?(ExtraField) ? extra : ExtraField.new(extra.to_s)
         | 
| 98 103 | 
             
                  end
         | 
| 99 104 | 
             
                  new_entry.compression_method = compression_method unless compression_method.nil?
         | 
| 100 105 | 
             
                  init_next_entry(new_entry, level)
         | 
| @@ -104,7 +109,8 @@ module Zip | |
| 104 109 | 
             
                def copy_raw_entry(entry)
         | 
| 105 110 | 
             
                  entry = entry.dup
         | 
| 106 111 | 
             
                  raise Error, 'zip stream is closed' if @closed
         | 
| 107 | 
            -
                  raise Error, 'entry is not a ZipEntry' unless entry. | 
| 112 | 
            +
                  raise Error, 'entry is not a ZipEntry' unless entry.kind_of?(Entry)
         | 
| 113 | 
            +
             | 
| 108 114 | 
             
                  finalize_current_entry
         | 
| 109 115 | 
             
                  @entry_set << entry
         | 
| 110 116 | 
             
                  src_pos = entry.local_header_offset
         | 
| @@ -123,8 +129,11 @@ module Zip | |
| 123 129 |  | 
| 124 130 | 
             
                def finalize_current_entry
         | 
| 125 131 | 
             
                  return unless @current_entry
         | 
| 132 | 
            +
             | 
| 126 133 | 
             
                  finish
         | 
| 127 | 
            -
                  @current_entry.compressed_size = @output_stream.tell -  | 
| 134 | 
            +
                  @current_entry.compressed_size = @output_stream.tell - \
         | 
| 135 | 
            +
                                                   @current_entry.local_header_offset - \
         | 
| 136 | 
            +
                                                   @current_entry.calculate_local_header_size
         | 
| 128 137 | 
             
                  @current_entry.size = @compressor.size
         | 
| 129 138 | 
             
                  @current_entry.crc = @compressor.crc
         | 
| 130 139 | 
             
                  @output_stream << @encrypter.data_descriptor(@current_entry.crc, @current_entry.compressed_size, @current_entry.size)
         | 
| @@ -144,9 +153,9 @@ module Zip | |
| 144 153 |  | 
| 145 154 | 
             
                def get_compressor(entry, level)
         | 
| 146 155 | 
             
                  case entry.compression_method
         | 
| 147 | 
            -
                  when Entry::DEFLATED | 
| 156 | 
            +
                  when Entry::DEFLATED
         | 
| 148 157 | 
             
                    ::Zip::Deflater.new(@output_stream, level, @encrypter)
         | 
| 149 | 
            -
                  when Entry::STORED | 
| 158 | 
            +
                  when Entry::STORED
         | 
| 150 159 | 
             
                    ::Zip::PassThruCompressor.new(@output_stream)
         | 
| 151 160 | 
             
                  else
         | 
| 152 161 | 
             
                    raise ::Zip::CompressionMethodError,
         |