rubyzip 0.9.9 → 1.0.0.beta1

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

Potentially problematic release.


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

Files changed (46) hide show
  1. checksums.yaml +7 -0
  2. data/NEWS +9 -5
  3. data/README.md +79 -21
  4. data/Rakefile +1 -1
  5. data/lib/zip.rb +52 -0
  6. data/lib/zip/central_directory.rb +135 -0
  7. data/lib/zip/constants.rb +57 -7
  8. data/lib/zip/decompressor.rb +2 -2
  9. data/lib/zip/deflater.rb +11 -12
  10. data/lib/zip/dos_time.rb +9 -9
  11. data/lib/zip/entry.rb +609 -0
  12. data/lib/zip/entry_set.rb +86 -0
  13. data/lib/zip/errors.rb +8 -0
  14. data/lib/zip/extra_field.rb +90 -0
  15. data/lib/zip/extra_field/generic.rb +43 -0
  16. data/lib/zip/extra_field/universal_time.rb +47 -0
  17. data/lib/zip/extra_field/unix.rb +39 -0
  18. data/lib/zip/{zip_file.rb → file.rb} +140 -61
  19. data/lib/zip/{zipfilesystem.rb → filesystem.rb} +12 -12
  20. data/lib/zip/inflater.rb +24 -24
  21. data/lib/zip/{zip_input_stream.rb → input_stream.rb} +11 -10
  22. data/lib/zip/ioextras.rb +145 -123
  23. data/lib/zip/null_compressor.rb +1 -1
  24. data/lib/zip/null_decompressor.rb +5 -3
  25. data/lib/zip/null_input_stream.rb +2 -2
  26. data/lib/zip/{zip_output_stream.rb → output_stream.rb} +43 -41
  27. data/lib/zip/pass_thru_compressor.rb +2 -2
  28. data/lib/zip/pass_thru_decompressor.rb +17 -16
  29. data/lib/zip/{zip_streamable_directory.rb → streamable_directory.rb} +1 -1
  30. data/lib/zip/{zip_streamable_stream.rb → streamable_stream.rb} +2 -2
  31. data/lib/zip/version.rb +3 -0
  32. data/samples/example.rb +27 -5
  33. data/samples/example_filesystem.rb +2 -2
  34. data/samples/example_recursive.rb +1 -1
  35. data/samples/gtkRubyzip.rb +1 -1
  36. data/samples/qtzip.rb +2 -2
  37. data/samples/write_simple.rb +1 -1
  38. data/samples/zipfind.rb +1 -1
  39. metadata +29 -27
  40. data/lib/zip/settings.rb +0 -10
  41. data/lib/zip/tempfile_bugfixed.rb +0 -195
  42. data/lib/zip/zip.rb +0 -56
  43. data/lib/zip/zip_central_directory.rb +0 -135
  44. data/lib/zip/zip_entry.rb +0 -638
  45. data/lib/zip/zip_entry_set.rb +0 -77
  46. data/lib/zip/zip_extra_field.rb +0 -213
@@ -15,7 +15,7 @@ module Zip
15
15
  yield(fileName)
16
16
  if zipFilePattern.match(fileName) && File.file?(fileName)
17
17
  begin
18
- Zip::ZipFile.foreach(fileName) {
18
+ Zip::File.foreach(fileName) {
19
19
  |zipEntry|
20
20
  yield(fileName + File::SEPARATOR + zipEntry.to_s)
21
21
  }
metadata CHANGED
@@ -1,18 +1,18 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubyzip
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.9
5
- prerelease:
4
+ version: 1.0.0.beta1
6
5
  platform: ruby
7
6
  authors:
8
- - Alan Harper
7
+ - Alexander Simonov
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2012-06-17 00:00:00.000000000 Z
11
+ date: 2013-08-21 00:00:00.000000000 Z
13
12
  dependencies: []
14
13
  description:
15
- email: alan@aussiegeek.net
14
+ email:
15
+ - alex@simonov.me
16
16
  executables: []
17
17
  extensions: []
18
18
  extra_rdoc_files: []
@@ -24,57 +24,59 @@ files:
24
24
  - samples/qtzip.rb
25
25
  - samples/write_simple.rb
26
26
  - samples/zipfind.rb
27
+ - lib/zip/central_directory.rb
27
28
  - lib/zip/compressor.rb
28
29
  - lib/zip/constants.rb
29
30
  - lib/zip/decompressor.rb
30
31
  - lib/zip/deflater.rb
31
32
  - lib/zip/dos_time.rb
33
+ - lib/zip/entry.rb
34
+ - lib/zip/entry_set.rb
35
+ - lib/zip/errors.rb
36
+ - lib/zip/extra_field/generic.rb
37
+ - lib/zip/extra_field/universal_time.rb
38
+ - lib/zip/extra_field/unix.rb
39
+ - lib/zip/extra_field.rb
40
+ - lib/zip/file.rb
41
+ - lib/zip/filesystem.rb
32
42
  - lib/zip/inflater.rb
43
+ - lib/zip/input_stream.rb
33
44
  - lib/zip/ioextras.rb
34
45
  - lib/zip/null_compressor.rb
35
46
  - lib/zip/null_decompressor.rb
36
47
  - lib/zip/null_input_stream.rb
48
+ - lib/zip/output_stream.rb
37
49
  - lib/zip/pass_thru_compressor.rb
38
50
  - lib/zip/pass_thru_decompressor.rb
39
- - lib/zip/settings.rb
40
- - lib/zip/tempfile_bugfixed.rb
41
- - lib/zip/zip.rb
42
- - lib/zip/zip_central_directory.rb
43
- - lib/zip/zip_entry.rb
44
- - lib/zip/zip_entry_set.rb
45
- - lib/zip/zip_extra_field.rb
46
- - lib/zip/zip_file.rb
47
- - lib/zip/zip_input_stream.rb
48
- - lib/zip/zip_output_stream.rb
49
- - lib/zip/zip_streamable_directory.rb
50
- - lib/zip/zip_streamable_stream.rb
51
- - lib/zip/zipfilesystem.rb
51
+ - lib/zip/streamable_directory.rb
52
+ - lib/zip/streamable_stream.rb
53
+ - lib/zip/version.rb
54
+ - lib/zip.rb
52
55
  - README.md
53
56
  - NEWS
54
57
  - TODO
55
58
  - Rakefile
56
- homepage: http://github.com/aussiegeek/rubyzip
59
+ homepage: http://github.com/rubyzip/rubyzip
57
60
  licenses: []
61
+ metadata: {}
58
62
  post_install_message:
59
63
  rdoc_options: []
60
64
  require_paths:
61
65
  - lib
62
66
  required_ruby_version: !ruby/object:Gem::Requirement
63
- none: false
64
67
  requirements:
65
- - - ! '>='
68
+ - - '>='
66
69
  - !ruby/object:Gem::Version
67
- version: 1.8.7
70
+ version: 1.9.2
68
71
  required_rubygems_version: !ruby/object:Gem::Requirement
69
- none: false
70
72
  requirements:
71
- - - ! '>='
73
+ - - '>'
72
74
  - !ruby/object:Gem::Version
73
- version: '0'
75
+ version: 1.3.1
74
76
  requirements: []
75
77
  rubyforge_project:
76
- rubygems_version: 1.8.24
78
+ rubygems_version: 2.0.6
77
79
  signing_key:
78
- specification_version: 3
80
+ specification_version: 4
79
81
  summary: rubyzip is a ruby module for reading and writing zip files
80
82
  test_files: []
@@ -1,10 +0,0 @@
1
- module Zip
2
- class << self
3
- def options
4
- @options ||= {
5
- :on_exists_proc => false,
6
- :continue_on_exists_proc => false
7
- }
8
- end
9
- end
10
- end
@@ -1,195 +0,0 @@
1
- #
2
- # tempfile - manipulates temporary files
3
- #
4
- # $Id: tempfile_bugfixed.rb,v 1.2 2005/02/19 20:30:33 thomas Exp $
5
- #
6
-
7
- require 'delegate'
8
- require 'tmpdir'
9
-
10
- module BugFix #:nodoc:all
11
-
12
- # A class for managing temporary files. This library is written to be
13
- # thread safe.
14
- class Tempfile < DelegateClass(File)
15
- MAX_TRY = 10
16
- @@cleanlist = []
17
-
18
- # Creates a temporary file of mode 0600 in the temporary directory
19
- # whose name is basename.pid.n and opens with mode "w+". A Tempfile
20
- # object works just like a File object.
21
- #
22
- # If tmpdir is omitted, the temporary directory is determined by
23
- # Dir::tmpdir provided by 'tmpdir.rb'.
24
- # When $SAFE > 0 and the given tmpdir is tainted, it uses
25
- # /tmp. (Note that ENV values are tainted by default)
26
- def initialize(basename, tmpdir=Dir::tmpdir)
27
- if $SAFE > 0 and tmpdir.tainted?
28
- tmpdir = '/tmp'
29
- end
30
-
31
- lock = nil
32
- n = failure = 0
33
-
34
- begin
35
- Thread.critical = true
36
-
37
- begin
38
- tmpname = sprintf('%s/%s%d.%d', tmpdir, basename, $$, n)
39
- lock = tmpname + '.lock'
40
- n += 1
41
- end while @@cleanlist.include?(tmpname) ||
42
- ::File.exist?(lock) || ::File.exist?(tmpname)
43
-
44
- Dir.mkdir(lock)
45
- rescue
46
- failure += 1
47
- retry if failure < MAX_TRY
48
- raise "cannot generate tempfile `%s'" % tmpname
49
- ensure
50
- Thread.critical = false
51
- end
52
-
53
- @data = [tmpname]
54
- @clean_proc = Tempfile.callback(@data)
55
- ObjectSpace.define_finalizer(self, @clean_proc)
56
-
57
- @tmpfile = ::File.open(tmpname, ::File::RDWR|::File::CREAT|::File::EXCL, 0600)
58
- @tmpname = tmpname
59
- @@cleanlist << @tmpname
60
- @data[1] = @tmpfile
61
- @data[2] = @@cleanlist
62
-
63
- super(@tmpfile)
64
-
65
- # Now we have all the File/IO methods defined, you must not
66
- # carelessly put bare puts(), etc. after this.
67
-
68
- Dir.rmdir(lock)
69
- end
70
-
71
- # Opens or reopens the file with mode "r+".
72
- def open
73
- @tmpfile.close if @tmpfile
74
- @tmpfile = ::File.open(@tmpname, 'r+')
75
- @data[1] = @tmpfile
76
- __setobj__(@tmpfile)
77
- end
78
-
79
- def _close # :nodoc:
80
- @tmpfile.close if @tmpfile
81
- @data[1] = @tmpfile = nil
82
- end
83
- protected :_close
84
-
85
- # Closes the file. If the optional flag is true, unlinks the file
86
- # after closing.
87
- #
88
- # If you don't explicitly unlink the temporary file, the removal
89
- # will be delayed until the object is finalized.
90
- def close(unlink_now=false)
91
- if unlink_now
92
- close!
93
- else
94
- _close
95
- end
96
- end
97
-
98
- # Closes and unlinks the file.
99
- def close!
100
- _close
101
- @clean_proc.call
102
- ObjectSpace.undefine_finalizer(self)
103
- end
104
-
105
- # Unlinks the file. On UNIX-like systems, it is often a good idea
106
- # to unlink a temporary file immediately after creating and opening
107
- # it, because it leaves other programs zero chance to access the
108
- # file.
109
- def unlink
110
- # keep this order for thread safeness
111
- ::File.unlink(@tmpname) if ::File.exist?(@tmpname)
112
- @@cleanlist.delete(@tmpname) if @@cleanlist
113
- end
114
- alias :delete :unlink
115
-
116
- if RUBY_VERSION > '1.8.0'
117
- def __setobj__(obj)
118
- @_dc_obj = obj
119
- end
120
- else
121
- def __setobj__(obj)
122
- @obj = obj
123
- end
124
- end
125
-
126
- # Returns the full path name of the temporary file.
127
- def path
128
- @tmpname
129
- end
130
-
131
- # Returns the size of the temporary file. As a side effect, the IO
132
- # buffer is flushed before determining the size.
133
- def size
134
- if @tmpfile
135
- @tmpfile.flush
136
- @tmpfile.stat.size
137
- else
138
- 0
139
- end
140
- end
141
- alias length size
142
-
143
- class << self
144
- def callback(data) # :nodoc:
145
- pid = $$
146
- lambda{
147
- if pid == $$
148
- path, tmpfile, cleanlist = *data
149
-
150
- print "removing ", path, "..." if $DEBUG
151
-
152
- tmpfile.close if tmpfile
153
-
154
- # keep this order for thread safeness
155
- ::File.unlink(path) if ::File.exist?(path)
156
- cleanlist.delete(path) if cleanlist
157
-
158
- print "done\n" if $DEBUG
159
- end
160
- }
161
- end
162
-
163
- # If no block is given, this is a synonym for new().
164
- #
165
- # If a block is given, it will be passed tempfile as an argument,
166
- # and the tempfile will automatically be closed when the block
167
- # terminates. In this case, open() returns nil.
168
- def open(*args)
169
- tempfile = new(*args)
170
-
171
- if block_given?
172
- begin
173
- yield(tempfile)
174
- ensure
175
- tempfile.close
176
- end
177
-
178
- nil
179
- else
180
- tempfile
181
- end
182
- end
183
- end
184
- end
185
-
186
- end # module BugFix
187
- if __FILE__ == $0
188
- # $DEBUG = true
189
- f = Tempfile.new("foo")
190
- f.print("foo\n")
191
- f.close
192
- f.open
193
- p f.gets # => "foo\n"
194
- f.close!
195
- end
@@ -1,56 +0,0 @@
1
- require 'delegate'
2
- require 'singleton'
3
- require 'tempfile'
4
- require 'fileutils'
5
- require 'stringio'
6
- require 'zlib'
7
- require 'zip/dos_time'
8
- require 'zip/ioextras'
9
- require 'rbconfig'
10
-
11
- require 'zip/zip_entry'
12
- require 'zip/zip_extra_field'
13
- require 'zip/zip_entry_set'
14
- require 'zip/zip_central_directory'
15
- require 'zip/zip_file'
16
- require 'zip/zip_input_stream'
17
- require 'zip/zip_output_stream'
18
- require 'zip/decompressor'
19
- require 'zip/compressor'
20
- require 'zip/null_decompressor'
21
- require 'zip/null_compressor'
22
- require 'zip/null_input_stream'
23
- require 'zip/pass_thru_compressor'
24
- require 'zip/pass_thru_decompressor'
25
- require 'zip/inflater'
26
- require 'zip/deflater'
27
- require 'zip/zip_streamable_stream'
28
- require 'zip/zip_streamable_directory'
29
- require 'zip/constants'
30
-
31
- require 'zip/settings'
32
-
33
- if Tempfile.superclass == SimpleDelegator
34
- require 'zip/tempfile_bugfixed'
35
- Tempfile = BugFix::Tempfile
36
- end
37
-
38
- module Zlib #:nodoc:all
39
- if !const_defined?(:MAX_WBITS)
40
- MAX_WBITS = Zlib::Deflate.MAX_WBITS
41
- end
42
- end
43
-
44
- module Zip
45
- class ZipError < StandardError ; end
46
-
47
- class ZipEntryExistsError < ZipError; end
48
- class ZipDestinationFileExistsError < ZipError; end
49
- class ZipCompressionMethodError < ZipError; end
50
- class ZipEntryNameError < ZipError; end
51
- class ZipInternalError < ZipError; end
52
- end
53
-
54
- # Copyright (C) 2002, 2003 Thomas Sondergaard
55
- # rubyzip is free software; you can redistribute it and/or
56
- # modify it under the terms of the ruby license.
@@ -1,135 +0,0 @@
1
- module Zip
2
- class ZipCentralDirectory
3
- include Enumerable
4
-
5
- END_OF_CENTRAL_DIRECTORY_SIGNATURE = 0x06054b50
6
- MAX_END_OF_CENTRAL_DIRECTORY_STRUCTURE_SIZE = 65536 + 18
7
- STATIC_EOCD_SIZE = 22
8
-
9
- attr_reader :comment
10
-
11
- # Returns an Enumerable containing the entries.
12
- def entries
13
- @entrySet.entries
14
- end
15
-
16
- def initialize(entries = ZipEntrySet.new, comment = "") #:nodoc:
17
- super()
18
- @entrySet = entries.kind_of?(ZipEntrySet) ? entries : ZipEntrySet.new(entries)
19
- @comment = comment
20
- end
21
-
22
- def write_to_stream(io) #:nodoc:
23
- offset = io.tell
24
- @entrySet.each { |entry| entry.write_c_dir_entry(io) }
25
- write_e_o_c_d(io, offset)
26
- end
27
-
28
- def write_e_o_c_d(io, offset) #:nodoc:
29
- tmp = [
30
- END_OF_CENTRAL_DIRECTORY_SIGNATURE,
31
- 0 , # @numberOfThisDisk
32
- 0 , # @numberOfDiskWithStartOfCDir
33
- @entrySet? @entrySet.size : 0 ,
34
- @entrySet? @entrySet.size : 0 ,
35
- cdir_size ,
36
- offset ,
37
- @comment ? @comment.length : 0
38
- ]
39
- io << tmp.pack('VvvvvVVv')
40
- io << @comment
41
- end
42
-
43
- private :write_e_o_c_d
44
-
45
- def cdir_size #:nodoc:
46
- # does not include eocd
47
- @entrySet.inject(0) do |value, entry|
48
- entry.cdir_header_size + value
49
- end
50
- end
51
-
52
- private :cdir_size
53
-
54
- def read_e_o_c_d(io) #:nodoc:
55
- buf = get_e_o_c_d(io)
56
- @numberOfThisDisk = ZipEntry.read_zip_short(buf)
57
- @numberOfDiskWithStartOfCDir = ZipEntry.read_zip_short(buf)
58
- @totalNumberOfEntriesInCDirOnThisDisk = ZipEntry.read_zip_short(buf)
59
- @size = ZipEntry.read_zip_short(buf)
60
- @sizeInBytes = ZipEntry.read_zip_long(buf)
61
- @cdirOffset = ZipEntry.read_zip_long(buf)
62
- commentLength = ZipEntry.read_zip_short(buf)
63
- if commentLength <= 0
64
- @comment = buf.slice!(0, buf.size)
65
- else
66
- @comment = buf.read(commentLength)
67
- end
68
- raise ZipError, "Zip consistency problem while reading eocd structure" unless buf.size == 0
69
- end
70
-
71
- def read_central_directory_entries(io) #:nodoc:
72
- begin
73
- io.seek(@cdirOffset, IO::SEEK_SET)
74
- rescue Errno::EINVAL
75
- raise ZipError, "Zip consistency problem while reading central directory entry"
76
- end
77
- @entrySet = ZipEntrySet.new
78
- @size.times do
79
- tmp = ZipEntry.read_c_dir_entry(io)
80
- @entrySet << tmp
81
- end
82
- end
83
-
84
- def read_from_stream(io) #:nodoc:
85
- read_e_o_c_d(io)
86
- read_central_directory_entries(io)
87
- end
88
-
89
- def get_e_o_c_d(io) #:nodoc:
90
- begin
91
- io.seek(-MAX_END_OF_CENTRAL_DIRECTORY_STRUCTURE_SIZE, IO::SEEK_END)
92
- rescue Errno::EINVAL
93
- io.seek(0, IO::SEEK_SET)
94
- end
95
- buf = io.read
96
- sigIndex = buf.rindex([END_OF_CENTRAL_DIRECTORY_SIGNATURE].pack('V'))
97
- raise ZipError, "Zip end of central directory signature not found" unless sigIndex
98
- buf = buf.slice!((sigIndex + 4)..(buf.bytesize))
99
-
100
- def buf.read(count)
101
- slice!(0, count)
102
- end
103
-
104
- buf
105
- end
106
-
107
- # For iterating over the entries.
108
- def each(&proc)
109
- @entrySet.each(&proc)
110
- end
111
-
112
- # Returns the number of entries in the central directory (and
113
- # consequently in the zip archive).
114
- def size
115
- @entrySet.size
116
- end
117
-
118
- def ZipCentralDirectory.read_from_stream(io) #:nodoc:
119
- cdir = new
120
- cdir.read_from_stream(io)
121
- return cdir
122
- rescue ZipError
123
- return nil
124
- end
125
-
126
- def ==(other) #:nodoc:
127
- return false unless other.kind_of?(ZipCentralDirectory)
128
- @entrySet.entries.sort == other.entries.sort && comment == other.comment
129
- end
130
- end
131
- end
132
-
133
- # Copyright (C) 2002, 2003 Thomas Sondergaard
134
- # rubyzip is free software; you can redistribute it and/or
135
- # modify it under the terms of the ruby license.