rubyzip 0.9.8 → 0.9.9

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.

data/NEWS CHANGED
@@ -1,3 +1,9 @@
1
+ = Version 0.9.9
2
+
3
+ Added support for backslashes in zip files (generated by the default Windows
4
+ zip packer for example) and comment sections with the comment length set to zero
5
+ even though there is actually a comment.
6
+
1
7
  = Version 0.9.8
2
8
 
3
9
  Fixed: "Unitialized constant NullInputStream" error
data/README.md CHANGED
@@ -1,10 +1,8 @@
1
- rubyzip [![Build Status](https://secure.travis-ci.org/aussiegeek/rubyzip.png)](http://travis-ci.org/aussiegeek/rubyzip)
2
- =======
1
+ # rubyzip [![Build Status](https://secure.travis-ci.org/aussiegeek/rubyzip.png)](http://travis-ci.org/aussiegeek/rubyzip)
3
2
 
4
3
  rubyzip is a ruby library for reading and writing zip files.
5
4
 
6
- Installation
7
- ------------
5
+ ## Installation
8
6
  rubyzip is available on RubyGems, so:
9
7
 
10
8
  ```
@@ -17,37 +15,30 @@ Or in your Gemfile:
17
15
  gem 'rubyzip'
18
16
  ```
19
17
 
20
- Developing
21
- ----------
18
+ ## Usage
22
19
 
23
- To run tests you need run next commands:
24
-
25
- ```
26
- bundle install
27
- rake
28
- ```
29
-
30
- Configuration
31
- -------------
32
-
33
- By default, rubyzip will not overwrite files if they already exist inside of the extracted path. To change this behavior, you may specify a configuration option like so:
34
-
35
- ```
36
- Zip.options[:on_exists_proc] = true
37
- ```
20
+ ### Basic zip archive creation
38
21
 
39
- If you're using rubyzip with rails, consider placing this snippet of code in an initializer file such as `config/initializers/rubyzip.rb`
40
-
41
- Additionally, if you want to configure rubyzip to overwrite existing files while creating a .zip file, you can do so with the following:
42
-
43
- ```
44
- Zip.options[:continue_on_exists_proc] = true
22
+ ```ruby
23
+ require 'rubygems'
24
+ require 'zip/zip'
25
+
26
+ folder = "Users/me/Desktop/stuff_to_zip"
27
+ input_filenames = ['image.jpg', 'description.txt', 'stats.csv']
28
+
29
+ zipfile_name = "/Users/me/Desktop/archive.zip"
30
+
31
+ Zip::ZipFile.open(zipfile_name, Zip::ZipFile::CREATE) do |zipfile|
32
+ input_filenames.each do |filename|
33
+ # Two arguments:
34
+ # - The name of the file as it will appear in the archive
35
+ # - The original file, including the path to find it
36
+ zipfile.add(filename, folder + '/' + filename)
37
+ end
38
+ end
45
39
  ```
46
40
 
47
-
48
- Documentation
49
- -------------
50
-
41
+ ## Further Documentation
51
42
 
52
43
  There is more than one way to access or create a zip archive with
53
44
  rubyzip. The basic API is modeled after the classes in
@@ -76,22 +67,39 @@ For details about the specific behaviour of classes and methods refer
76
67
  to the test suite. Finally you can generate the rdoc documentation or
77
68
  visit http://rubyzip.sourceforge.net.
78
69
 
79
- License
80
- -------
81
70
 
82
- rubyzip is distributed under the same license as ruby. See
83
- http://www.ruby-lang.org/en/LICENSE.txt
71
+ ## Configuration
84
72
 
73
+ By default, rubyzip will not overwrite files if they already exist inside of the extracted path. To change this behavior, you may specify a configuration option like so:
85
74
 
86
- Website and Project Home
87
- ------------------------
75
+ ```
76
+ Zip.options[:on_exists_proc] = true
77
+ ```
78
+
79
+ If you're using rubyzip with rails, consider placing this snippet of code in an initializer file such as `config/initializers/rubyzip.rb`
80
+
81
+ Additionally, if you want to configure rubyzip to overwrite existing files while creating a .zip file, you can do so with the following:
82
+
83
+ ```
84
+ Zip.options[:continue_on_exists_proc] = true
85
+ ```
86
+
87
+ ## Developing
88
+
89
+ To run tests you need run next commands:
90
+
91
+ ```
92
+ bundle install
93
+ rake
94
+ ```
95
+
96
+ ## Website and Project Home
88
97
 
89
98
  http://github.com/aussiegeek/rubyzip
90
99
 
91
100
  http://rdoc.info/github/aussiegeek/rubyzip/master/frames
92
101
 
93
- Authors
94
- -------
102
+ ## Authors
95
103
 
96
104
  Alexander Simonov ( alex at simonov.me)
97
105
 
@@ -102,3 +110,8 @@ Thomas Sondergaard (thomas at sondergaard.cc)
102
110
  Technorama Ltd. (oss-ruby-zip at technorama.net)
103
111
 
104
112
  extra-field support contributed by Tatsuki Sugiura (sugi at nemui.org)
113
+
114
+ ## License
115
+
116
+ rubyzip is distributed under the same license as ruby. See
117
+ http://www.ruby-lang.org/en/LICENSE.txt
@@ -1,5 +1,4 @@
1
1
  require 'delegate'
2
- require 'iconv' unless RUBY_VERSION >= '1.9'
3
2
  require 'singleton'
4
3
  require 'tempfile'
5
4
  require 'fileutils'
@@ -60,7 +60,11 @@ module Zip
60
60
  @sizeInBytes = ZipEntry.read_zip_long(buf)
61
61
  @cdirOffset = ZipEntry.read_zip_long(buf)
62
62
  commentLength = ZipEntry.read_zip_short(buf)
63
- @comment = buf.read(commentLength)
63
+ if commentLength <= 0
64
+ @comment = buf.slice!(0, buf.size)
65
+ else
66
+ @comment = buf.read(commentLength)
67
+ end
64
68
  raise ZipError, "Zip consistency problem while reading eocd structure" unless buf.size == 0
65
69
  end
66
70
 
@@ -87,25 +91,11 @@ module Zip
87
91
  io.seek(-MAX_END_OF_CENTRAL_DIRECTORY_STRUCTURE_SIZE, IO::SEEK_END)
88
92
  rescue Errno::EINVAL
89
93
  io.seek(0, IO::SEEK_SET)
90
- rescue Errno::EFBIG # FreeBSD 4.9 raise Errno::EFBIG instead of Errno::EINVAL
91
- io.seek(0, IO::SEEK_SET)
92
94
  end
93
-
94
- # 'buf = io.read' substituted with lump of code to work around FreeBSD 4.5 issue
95
- retried = false
96
- buf = nil
97
- begin
98
- buf = io.read
99
- rescue Errno::EFBIG # FreeBSD 4.5 may raise Errno::EFBIG
100
- raise if (retried)
101
- retried = true
102
- io.seek(0, IO::SEEK_SET)
103
- retry
104
- end
105
-
95
+ buf = io.read
106
96
  sigIndex = buf.rindex([END_OF_CENTRAL_DIRECTORY_SIGNATURE].pack('V'))
107
97
  raise ZipError, "Zip end of central directory signature not found" unless sigIndex
108
- buf = buf.slice!((sigIndex + 4)...(buf.bytesize))
98
+ buf = buf.slice!((sigIndex + 4)..(buf.bytesize))
109
99
 
110
100
  def buf.read(count)
111
101
  slice!(0, count)
@@ -260,7 +260,7 @@ module Zip
260
260
 
261
261
  @name = io.read(nameLength)
262
262
  extra = io.read(extraLength)
263
-
263
+ until @name.sub!('\\', '/') == nil do end # some zip files use backslashes instead of slashes as path separators
264
264
  if (extra && extra.bytesize != extraLength)
265
265
  raise ZipError, "Truncated local zip entry header"
266
266
  else
@@ -332,6 +332,7 @@ module Zip
332
332
  set_time(lastModDate, lastModTime)
333
333
 
334
334
  @name = io.read(nameLength)
335
+ until @name.sub!('\\', '/') == nil do end # some zip files use backslashes instead of slashes as path separators
335
336
  if ZipExtraField === @extra
336
337
  @extra.merge(io.read(extraLength))
337
338
  else
@@ -54,9 +54,11 @@ module Zip
54
54
  end
55
55
 
56
56
  def glob(pattern, flags = ::File::FNM_PATHNAME|::File::FNM_DOTMATCH)
57
- entries.select do |entry|
58
- ::File.fnmatch(pattern, entry.name.chomp('/'), flags)
59
- end
57
+ entries.map do |entry|
58
+ next nil unless ::File.fnmatch(pattern, entry.name.chomp('/'), flags)
59
+ yield(entry) if block_given?
60
+ entry
61
+ end.compact
60
62
  end
61
63
 
62
64
  #TODO attr_accessor :auto_create_directories
@@ -103,6 +103,24 @@ module Zip
103
103
  zf.write_buffer
104
104
  end
105
105
 
106
+ # Like #open, but reads zip archive contents from a String or open IO
107
+ # stream, and outputs data to a buffer.
108
+ # (This can be used to extract data from a
109
+ # downloaded zip archive without first saving it to disk.)
110
+ def open_buffer(io)
111
+ zf = ZipFile.new('',true,true)
112
+ if io.is_a? IO
113
+ zf.read_from_stream(io)
114
+ elsif io.is_a? String
115
+ require 'stringio'
116
+ zf.read_from_stream(StringIO.new(io))
117
+ else
118
+ raise "Zip::ZipFile.open_buffer expects an argument of class String or IO. Found: #{io.class}"
119
+ end
120
+ yield zf
121
+ zf.write_buffer
122
+ end
123
+
106
124
  # Iterates over the contents of the ZipFile. This is more efficient
107
125
  # than using a ZipInputStream since this methods simply iterates
108
126
  # through the entries in the central directory structure in the archive
@@ -239,6 +257,11 @@ module Zip
239
257
  @entrySet.find_entry(entry_name)
240
258
  end
241
259
 
260
+ # Searches for entries given a glob
261
+ def glob(*args,&block)
262
+ @entrySet.glob(*args,&block)
263
+ end
264
+
242
265
  # Searches for an entry just as find_entry, but throws Errno::ENOENT
243
266
  # if no entry is found.
244
267
  def get_entry(entry)
@@ -467,6 +467,10 @@ module Zip
467
467
  entries
468
468
  end
469
469
 
470
+ def glob(*args,&block)
471
+ @mappedZip.glob(*args,&block)
472
+ end
473
+
470
474
  def foreach(aDirectoryName)
471
475
  unless @file.stat(aDirectoryName).directory?
472
476
  raise Errno::ENOTDIR, aDirectoryName
metadata CHANGED
@@ -1,27 +1,22 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: rubyzip
3
- version: !ruby/object:Gem::Version
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.9.9
4
5
  prerelease:
5
- version: 0.9.8
6
6
  platform: ruby
7
- authors:
7
+ authors:
8
8
  - Alan Harper
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
-
13
- date: 2012-04-26 00:00:00 Z
12
+ date: 2012-06-17 00:00:00.000000000 Z
14
13
  dependencies: []
15
-
16
14
  description:
17
15
  email: alan@aussiegeek.net
18
16
  executables: []
19
-
20
17
  extensions: []
21
-
22
18
  extra_rdoc_files: []
23
-
24
- files:
19
+ files:
25
20
  - samples/example.rb
26
21
  - samples/example_filesystem.rb
27
22
  - samples/example_recursive.rb
@@ -60,31 +55,26 @@ files:
60
55
  - Rakefile
61
56
  homepage: http://github.com/aussiegeek/rubyzip
62
57
  licenses: []
63
-
64
58
  post_install_message:
65
59
  rdoc_options: []
66
-
67
- require_paths:
60
+ require_paths:
68
61
  - lib
69
- required_ruby_version: !ruby/object:Gem::Requirement
62
+ required_ruby_version: !ruby/object:Gem::Requirement
70
63
  none: false
71
- requirements:
72
- - - ">="
73
- - !ruby/object:Gem::Version
64
+ requirements:
65
+ - - ! '>='
66
+ - !ruby/object:Gem::Version
74
67
  version: 1.8.7
75
- required_rubygems_version: !ruby/object:Gem::Requirement
68
+ required_rubygems_version: !ruby/object:Gem::Requirement
76
69
  none: false
77
- requirements:
78
- - - ">="
79
- - !ruby/object:Gem::Version
80
- version: "0"
70
+ requirements:
71
+ - - ! '>='
72
+ - !ruby/object:Gem::Version
73
+ version: '0'
81
74
  requirements: []
82
-
83
75
  rubyforge_project:
84
- rubygems_version: 1.8.19
76
+ rubygems_version: 1.8.24
85
77
  signing_key:
86
78
  specification_version: 3
87
79
  summary: rubyzip is a ruby module for reading and writing zip files
88
80
  test_files: []
89
-
90
- has_rdoc: