multi_zip 0.1.3 → 0.1.4
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 +4 -4
- data/.gitignore +1 -0
- data/.travis.yml +4 -3
- data/Gemfile +1 -2
- data/Guardfile +0 -63
- data/README.md +14 -66
- data/TODO.md +49 -0
- data/lib/multi_zip/errors.rb +29 -6
- data/lib/multi_zip/version.rb +1 -1
- data/lib/multi_zip.rb +2 -2
- data/multi_zip.gemspec +10 -2
- data/spec/backend_shared_example.rb +51 -72
- data/spec/fixtures/empty.zip +0 -0
- data/spec/fixtures/test/.gitkeep +0 -0
- data/spec/spec_helper.rb +16 -5
- metadata +9 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b4d9becd80958a0eb07dab22a0207dfcb91ebe00
|
4
|
+
data.tar.gz: eb1092f782ab4fc2e6933eb5a36b84036bf9cfca
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9a6eca1072c53f5266e9e8afdee331b7df518df68ebceb5a10b9120fc9041e3710552fdcd557eba80ed51ec95692864b2724cf11f64afa0f5986fc1883412e7d
|
7
|
+
data.tar.gz: e90c64a98a10a98dcedda42f190d1551a507f83166d3ea5612f0996e6a47e8d7b9a8d087998caeee975d8b146c3984bdf3e2f848fe5d9723549bf5ca2e43c7f2
|
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
language: ruby
|
2
2
|
rvm:
|
3
|
-
- ruby-head
|
4
3
|
- ree
|
5
4
|
- 1.8.7
|
6
5
|
- 1.9.3
|
7
6
|
- 2.0.0
|
8
|
-
- 2.1.
|
9
|
-
- 2.2.
|
7
|
+
- 2.1.8
|
8
|
+
- 2.2.4
|
9
|
+
- 2.3.0
|
10
10
|
- jruby-18mode
|
11
11
|
- jruby-19mode
|
12
12
|
- rbx-2
|
@@ -15,3 +15,4 @@ matrix:
|
|
15
15
|
- rvm:
|
16
16
|
- ruby-head
|
17
17
|
- rbx-2
|
18
|
+
sudo: false
|
data/Gemfile
CHANGED
data/Guardfile
CHANGED
@@ -1,43 +1,7 @@
|
|
1
|
-
# A sample Guardfile
|
2
|
-
# More info at https://github.com/guard/guard#readme
|
3
|
-
|
4
|
-
## Uncomment and set this to only include directories you want to watch
|
5
|
-
# directories %w(app lib config test spec features)
|
6
|
-
|
7
|
-
## Uncomment to clear the screen before every task
|
8
|
-
# clearing :on
|
9
|
-
|
10
|
-
## Guard internally checks for changes in the Guardfile and exits.
|
11
|
-
## If you want Guard to automatically start up again, run guard in a
|
12
|
-
## shell loop, e.g.:
|
13
|
-
##
|
14
|
-
## $ while bundle exec guard; do echo "Restarting Guard..."; done
|
15
|
-
##
|
16
|
-
## Note: if you are using the `directories` clause above and you are not
|
17
|
-
## watching the project directory ('.'), then you will want to move
|
18
|
-
## the Guardfile to a watched dir and symlink it back, e.g.
|
19
|
-
#
|
20
|
-
# $ mkdir config
|
21
|
-
# $ mv Guardfile config/
|
22
|
-
# $ ln -s config/Guardfile .
|
23
|
-
#
|
24
|
-
# and, you'll have to watch "config/Guardfile" instead of "Guardfile"
|
25
|
-
|
26
|
-
# Note: The cmd option is now required due to the increasing number of ways
|
27
|
-
# rspec may be run, below are examples of the most common uses.
|
28
|
-
# * bundler: 'bundle exec rspec'
|
29
|
-
# * bundler binstubs: 'bin/rspec'
|
30
|
-
# * spring: 'bin/rspec' (This will use spring if running and you have
|
31
|
-
# installed the spring binstubs per the docs)
|
32
|
-
# * zeus: 'zeus rspec' (requires the server to be started separately)
|
33
|
-
# * 'just' rspec: 'rspec'
|
34
|
-
|
35
1
|
guard :rspec, cmd: "bundle exec rspec" do
|
36
2
|
require "guard/rspec/dsl"
|
37
3
|
dsl = Guard::RSpec::Dsl.new(self)
|
38
4
|
|
39
|
-
# Feel free to open issues for suggestions and improvements
|
40
|
-
|
41
5
|
# RSpec files
|
42
6
|
rspec = dsl.rspec
|
43
7
|
watch(rspec.spec_helper) { rspec.spec_dir }
|
@@ -47,31 +11,4 @@ guard :rspec, cmd: "bundle exec rspec" do
|
|
47
11
|
# Ruby files
|
48
12
|
ruby = dsl.ruby
|
49
13
|
dsl.watch_spec_files_for(ruby.lib_files)
|
50
|
-
|
51
|
-
# Rails files
|
52
|
-
rails = dsl.rails(view_extensions: %w(erb haml slim))
|
53
|
-
dsl.watch_spec_files_for(rails.app_files)
|
54
|
-
dsl.watch_spec_files_for(rails.views)
|
55
|
-
|
56
|
-
watch(rails.controllers) do |m|
|
57
|
-
[
|
58
|
-
rspec.spec.("routing/#{m[1]}_routing"),
|
59
|
-
rspec.spec.("controllers/#{m[1]}_controller"),
|
60
|
-
rspec.spec.("acceptance/#{m[1]}")
|
61
|
-
]
|
62
|
-
end
|
63
|
-
|
64
|
-
# Rails config changes
|
65
|
-
watch(rails.spec_helper) { rspec.spec_dir }
|
66
|
-
watch(rails.routes) { "#{rspec.spec_dir}/routing" }
|
67
|
-
watch(rails.app_controller) { "#{rspec.spec_dir}/controllers" }
|
68
|
-
|
69
|
-
# Capybara features specs
|
70
|
-
watch(rails.view_dirs) { |m| rspec.spec.("features/#{m[1]}") }
|
71
|
-
|
72
|
-
# Turnip features and steps
|
73
|
-
watch(%r{^spec/acceptance/(.+)\.feature$})
|
74
|
-
watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) do |m|
|
75
|
-
Dir[File.join("**/#{m[1]}.feature")][0] || "spec/acceptance"
|
76
|
-
end
|
77
14
|
end
|
data/README.md
CHANGED
@@ -12,8 +12,8 @@ It currently supports `.zip` archives only. See TODO for info on others.
|
|
12
12
|
MultiZip provides a very small and focused set of functions:
|
13
13
|
|
14
14
|
* Create a new zip archive or open existing one.
|
15
|
-
* Add files to
|
16
|
-
* Read files from
|
15
|
+
* Add files to an archive from a file a variable.
|
16
|
+
* Read files from an archive in to a variable.
|
17
17
|
* Extract files from an archive to a local file.
|
18
18
|
* List files contained in an archive.
|
19
19
|
* Delete files from an archive.
|
@@ -43,7 +43,8 @@ Do the standard dance: Either add `gem 'multi_zip'` to your Gemfile or run
|
|
43
43
|
`gem install multi_zip`.
|
44
44
|
|
45
45
|
__IMPORTANT NEXT STEP:__ You will also need a zip backend gem installed and
|
46
|
-
required. See
|
46
|
+
required. See [Supported Backend Gems](#supported-backend-gems) for a list of
|
47
|
+
which ones can be used.
|
47
48
|
|
48
49
|
## Getting started
|
49
50
|
|
@@ -81,13 +82,13 @@ You can also check which of these supported backends is currently available:
|
|
81
82
|
|
82
83
|
```ruby
|
83
84
|
> MultiZip.available_backends
|
84
|
-
=> []
|
85
|
+
=> []
|
85
86
|
> require 'archive/zip'
|
86
|
-
=> true
|
87
|
+
=> true
|
87
88
|
> MultiZip.available_backends
|
88
|
-
=> [:archive_zip]
|
89
|
+
=> [:archive_zip]
|
89
90
|
> require 'zip'
|
90
|
-
=> true
|
91
|
+
=> true
|
91
92
|
> MultiZip.available_backends
|
92
93
|
=> [:rubyzip, :archive_zip]
|
93
94
|
```
|
@@ -162,7 +163,7 @@ file = zip.remove_members([
|
|
162
163
|
# => true
|
163
164
|
```
|
164
165
|
|
165
|
-
#### Creating a new instance and passing a block
|
166
|
+
#### Creating a new instance and passing a block
|
166
167
|
|
167
168
|
`.new` can accept a block:
|
168
169
|
|
@@ -212,7 +213,7 @@ This behaviour is likely to change in future versions; see the below section
|
|
212
213
|
that talks about the `#close` method for more information.
|
213
214
|
|
214
215
|
#### `#close` method is currently a non-op
|
215
|
-
|
216
|
+
|
216
217
|
You'll notice that there is a `#close` method, but you may not know that it
|
217
218
|
doesn't yet do anything since the underlying archive is not kept open between
|
218
219
|
method calls.
|
@@ -220,69 +221,16 @@ method calls.
|
|
220
221
|
However, you should still use `#close` where appropriate since this
|
221
222
|
behaviour is likely to change in the future.
|
222
223
|
|
223
|
-
####
|
224
|
-
|
225
|
-
Supporting MRI, Jruby and Rubinius covers 95% of the production-ruby market.
|
226
|
-
However, In the future I plan on **trying** to support:
|
227
|
-
|
228
|
-
* maglev
|
229
|
-
* ironruby
|
230
|
-
* macruby
|
231
|
-
|
232
|
-
The current travis-ci configuration only tests on Linux. Adding macruby
|
233
|
-
support also means testing on OS X. I would like to one-day test with MRI, Ironruby and Jruby on Windows.
|
224
|
+
#### Backend support on platforms
|
234
225
|
|
235
226
|
MultiZip is written in pure ruby and so it should be able to run on any
|
236
227
|
runtime that is compatible with MRI 1.8.7; however, the backend gems it uses
|
237
228
|
may or may not work on every platform -- which is one of the reasons this
|
238
|
-
gem exists in the first place!
|
239
|
-
|
240
|
-
|
229
|
+
gem exists in the first place!
|
230
|
+
|
241
231
|
## TODO
|
242
232
|
|
243
|
-
|
244
|
-
|
245
|
-
* #add_member: add file to archive from filesystem (new method).
|
246
|
-
* Document exceptions raised, what they mean and how to use them.
|
247
|
-
* Add inline docs for methods.
|
248
|
-
* support *nix zip(1L)/unzip(1L) without needing backend gem (with warning).
|
249
|
-
|
250
|
-
Other things that need to be done, in no particular order:
|
251
|
-
|
252
|
-
* Add support for more backends.
|
253
|
-
* Support for backend gems to process other formats (gzip, bzip2, 7zip, tar, etc).
|
254
|
-
* Keep the backend archive open between method calls.
|
255
|
-
* Add soak tests for memory usage once archived are kept open.
|
256
|
-
* Ensure #close is executed when MultiZip instance goes out of scope.
|
257
|
-
* Option to overwrite and existing archive instead of adding to it.
|
258
|
-
* #extract_member: extract file to path using original member name.
|
259
|
-
* #write_member: support for reading from IO streams.
|
260
|
-
* test with different majour versions of current supported backends.
|
261
|
-
* Standardize Exception classes and when to raise them.
|
262
|
-
* #read_*, #extract_* and #write_* methods should accept a block.
|
263
|
-
* #extract_members: extract multiple files with one command (new method).
|
264
|
-
* #write_member: add entire directory (recursively or not) to archive.
|
265
|
-
* #write_members: add multiple files by wildcard (new method).
|
266
|
-
* #add_members: add multiple files to archive from filesystem (new method).
|
267
|
-
* #remove_members: remove multiple member files from the archive (new_method).
|
268
|
-
* #read_members: read multiple files wildcard.
|
269
|
-
* #read_members: read multiple files via prefix as #list_members does.
|
270
|
-
* #extract_members: extract multiple files via prefix as #list_members does (new method).
|
271
|
-
* #extract_members: extract multiple files wildcard (new method).
|
272
|
-
* #member_info: return information (name, size, etc) about member (new method).
|
273
|
-
* #read_member_stream: return member as IO Stream to keeping large amounts of data in memory (new method).
|
274
|
-
* Write guide to show others how they can add their own backends gems.
|
275
|
-
* #member_type: return the type of the member (new method).
|
276
|
-
* #member_exists?: accept an argument to specify the file type (file, dir, symlink, etc).
|
277
|
-
* Soak-test each backend to find memory leaks.
|
278
|
-
|
279
|
-
Things that I'd **like** to do, but that are probably not realistic because
|
280
|
-
they cannot be sufficiently abstracted across all backend gems:
|
281
|
-
|
282
|
-
* Ability to set location and compression format and level of archive.
|
283
|
-
* Ability to set compression format and level of individual members (for Epub compatibility).
|
284
|
-
* Ability to set archive location of individual members (for Epub compatibility).
|
285
|
-
* Support creating, reading from and writing to password-protected or encrypted archives.
|
233
|
+
See [TODO.md](TODO.md).
|
286
234
|
|
287
235
|
## Contributing
|
288
236
|
|
data/TODO.md
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
## MultiZip TODO
|
2
|
+
|
3
|
+
#### Most important things, in order of importance:
|
4
|
+
|
5
|
+
* #add_member: add file to archive from filesystem (new method).
|
6
|
+
* Document exceptions raised, what they mean and how to use them.
|
7
|
+
* Add inline docs for methods.
|
8
|
+
* support *nix zip(1L)/unzip(1L) without needing backend gem (with warning).
|
9
|
+
|
10
|
+
#### Other things that need to be done, in no particular order:
|
11
|
+
|
12
|
+
* Add support for more backends.
|
13
|
+
* Support for backend gems to process other formats (gzip, bzip2, 7zip, tar, etc).
|
14
|
+
* Keep the backend archive open between method calls.
|
15
|
+
* Add soak tests for memory usage once archived are kept open.
|
16
|
+
* Ensure #close is executed when MultiZip instance goes out of scope.
|
17
|
+
* Option to overwrite and existing archive instead of adding to it.
|
18
|
+
* #extract_member: extract file to path using original member name.
|
19
|
+
* #write_member: support for reading from IO streams.
|
20
|
+
* test with different majour versions of current supported backends.
|
21
|
+
* Standardize Exception classes and when to raise them.
|
22
|
+
* #read_*, #extract_* and #write_* methods should accept a block.
|
23
|
+
* #extract_members: extract multiple files with one command (new method).
|
24
|
+
* #write_member: add entire directory (recursively or not) to archive.
|
25
|
+
* #write_members: add multiple files by wildcard (new method).
|
26
|
+
* #add_members: add multiple files to archive from filesystem (new method).
|
27
|
+
* #remove_members: remove multiple member files from the archive (new_method).
|
28
|
+
* #read_members: read multiple files wildcard.
|
29
|
+
* #read_members: read multiple files via prefix as #list_members does.
|
30
|
+
* #extract_members: extract multiple files via prefix as #list_members does (new method).
|
31
|
+
* #extract_members: extract multiple files wildcard (new method).
|
32
|
+
* #member_info: return information (name, size, etc) about member (new method).
|
33
|
+
* #read_member_stream: return member as IO Stream to keeping large amounts of data in memory (new method).
|
34
|
+
* Write guide to show others how they can add their own backends gems.
|
35
|
+
* #member_type: return the type of the member (new method).
|
36
|
+
* #member_exists?: accept an argument to specify the file type (file, dir, symlink, etc).
|
37
|
+
* Soak-test each backend to find memory leaks.
|
38
|
+
|
39
|
+
#### Things that I'd **like** to do, but won't.
|
40
|
+
|
41
|
+
These are thinks that would be really nice to have but that are probably not
|
42
|
+
realistic because they cannot be abstracted across all backend gems:
|
43
|
+
|
44
|
+
* Ability to set location and compression format and level of archive.
|
45
|
+
* Ability to set compression format and level of individual members (for Epub compatibility).
|
46
|
+
* Ability to set archive location of individual members (for Epub compatibility).
|
47
|
+
* Support creating, reading from and writing to password-protected or encrypted archives.
|
48
|
+
* Support MagLev, IronRuby and MacRuby.
|
49
|
+
* Support Windows.
|
data/lib/multi_zip/errors.rb
CHANGED
@@ -1,7 +1,29 @@
|
|
1
1
|
class MultiZip
|
2
|
-
class BaseError < RuntimeError;
|
3
|
-
|
4
|
-
|
2
|
+
class BaseError < RuntimeError;
|
3
|
+
def to_s
|
4
|
+
if respond_to?(:message)
|
5
|
+
message
|
6
|
+
else
|
7
|
+
super
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
class NoSupportedBackendError < BaseError;
|
13
|
+
def message
|
14
|
+
"No supported backend found. Supported backends are #{MultiZip::BACKENDS.map(&:first).map(&:to_s).sort.join(', ')}"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
class InvalidBackendError < BaseError;
|
19
|
+
attr_reader :requested_backend
|
20
|
+
def initialize(requested_backend)
|
21
|
+
@requested_backend = requested_backend
|
22
|
+
end
|
23
|
+
def message
|
24
|
+
"The requested backend \"#{@requested_backend}\" was not found. Supported backends are #{MultiZip::BACKENDS.map(&:first).map(&:to_s).sort.join(', ')}"
|
25
|
+
end
|
26
|
+
end
|
5
27
|
|
6
28
|
class ArchiveError < BaseError
|
7
29
|
attr_reader :archive_filename, :original_exception
|
@@ -26,10 +48,11 @@ class MultiZip
|
|
26
48
|
def initialize(member_path)
|
27
49
|
@member_path = member_path
|
28
50
|
end
|
51
|
+
end
|
52
|
+
|
53
|
+
class MemberNotFoundError < MemberError
|
29
54
|
def message
|
30
55
|
"Member \"#{@member_path}\" not found."
|
31
56
|
end
|
32
57
|
end
|
33
|
-
|
34
|
-
class MemberNotFoundError < MemberError; end
|
35
|
-
end
|
58
|
+
end
|
data/lib/multi_zip/version.rb
CHANGED
data/lib/multi_zip.rb
CHANGED
@@ -53,7 +53,7 @@ class MultiZip
|
|
53
53
|
extend BACKENDS[@backend][:constant].call
|
54
54
|
return @backend
|
55
55
|
else
|
56
|
-
raise
|
56
|
+
raise InvalidBackendError.new(backend_name)
|
57
57
|
end
|
58
58
|
end
|
59
59
|
|
@@ -187,7 +187,7 @@ private
|
|
187
187
|
return name
|
188
188
|
end
|
189
189
|
end
|
190
|
-
raise NoSupportedBackendError
|
190
|
+
raise NoSupportedBackendError
|
191
191
|
end
|
192
192
|
end
|
193
193
|
|
data/multi_zip.gemspec
CHANGED
@@ -19,6 +19,14 @@ Gem::Specification.new do |spec|
|
|
19
19
|
spec.require_paths = ["lib"]
|
20
20
|
|
21
21
|
spec.add_development_dependency "bundler"
|
22
|
-
|
23
|
-
|
22
|
+
if RUBY_VERSION < '1.9'
|
23
|
+
# ruby 1.8.7 or ree
|
24
|
+
spec.add_development_dependency "rake", '10.1.1'
|
25
|
+
elsif RUBY_VERSION >= '1.9' && RUBY_VERSION < '2.0'
|
26
|
+
# 1.9.x
|
27
|
+
spec.add_development_dependency "rake", '11.1.2'
|
28
|
+
else
|
29
|
+
spec.add_development_dependency "rake"
|
30
|
+
end
|
31
|
+
spec.add_development_dependency "rspec", "~> 3.4.0"
|
24
32
|
end
|
@@ -1,15 +1,15 @@
|
|
1
1
|
shared_examples 'zip backend' do |backend_name|
|
2
|
-
|
3
|
-
|
2
|
+
context "backend: #{backend_name}" do
|
3
|
+
let(:filename) { archive_fixture_filename }
|
4
|
+
subject { MultiZip.new(filename, :backend => backend_name) }
|
4
5
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
6
|
+
before do
|
7
|
+
apply_constants(backend_name)
|
8
|
+
# subject.backend = backend_name
|
9
|
+
end
|
10
|
+
after { stash_constants(backend_name) }
|
10
11
|
|
11
|
-
|
12
|
-
context "backend: #{backend_name}" do
|
12
|
+
describe '#read_member' do
|
13
13
|
context 'member found' do
|
14
14
|
archive_member_files.each do |member_file|
|
15
15
|
it "returns '#{member_file}' as a string" do
|
@@ -30,13 +30,9 @@ shared_examples 'zip backend' do |backend_name|
|
|
30
30
|
it_behaves_like 'raises MemberNotFoundError', :read_member, archive_member_directories.first
|
31
31
|
end
|
32
32
|
|
33
|
-
|
34
|
-
it_behaves_like 'raises ArchiveNotFoundError', :read_member, archive_member_files.first
|
35
|
-
end
|
33
|
+
it_behaves_like 'archive not found, raises ArchiveNotFoundError', :read_member, archive_member_files.first
|
36
34
|
|
37
|
-
|
38
|
-
it 'raises ArchiveNotFoundError'
|
39
|
-
end
|
35
|
+
it_behaves_like 'archive is not a file, raises ArchiveNotFoundError', :read_member, archive_member_files.first
|
40
36
|
|
41
37
|
context 'archive cannot be accessed due to permissions' do
|
42
38
|
it 'raises ArchiveNotAccessibleError'
|
@@ -46,10 +42,8 @@ shared_examples 'zip backend' do |backend_name|
|
|
46
42
|
it_behaves_like 'raises InvalidArchiveError', :read_member, archive_member_files.first
|
47
43
|
end
|
48
44
|
end
|
49
|
-
end
|
50
45
|
|
51
|
-
|
52
|
-
context "backend: #{backend_name}" do
|
46
|
+
describe '#read_members' do
|
53
47
|
context 'all members found' do
|
54
48
|
it 'returns the member content as an array a string in order of args' do
|
55
49
|
extracted_files = subject.read_members(archive_member_files)
|
@@ -70,13 +64,9 @@ shared_examples 'zip backend' do |backend_name|
|
|
70
64
|
[ archive_member_files.first, 'doesnt_exist' ]
|
71
65
|
end
|
72
66
|
|
73
|
-
|
74
|
-
it_behaves_like 'raises ArchiveNotFoundError', :read_members, archive_member_files
|
75
|
-
end
|
67
|
+
it_behaves_like 'archive not found, raises ArchiveNotFoundError', :read_members, archive_member_files
|
76
68
|
|
77
|
-
|
78
|
-
it 'raises ArchiveNotFoundError'
|
79
|
-
end
|
69
|
+
it_behaves_like 'archive is not a file, raises ArchiveNotFoundError', :read_members, archive_member_files
|
80
70
|
|
81
71
|
context 'archive cannot be accessed due to permissions' do
|
82
72
|
it 'raises ArchiveNotAccessibleError'
|
@@ -87,10 +77,8 @@ shared_examples 'zip backend' do |backend_name|
|
|
87
77
|
[ archive_member_files.first, archive_member_directories.first ]
|
88
78
|
end
|
89
79
|
end
|
90
|
-
end
|
91
80
|
|
92
|
-
|
93
|
-
context "backend: #{backend_name}" do
|
81
|
+
describe '#extract_member' do
|
94
82
|
let(:tempfile) { Tempfile.new('multi_zip_test') }
|
95
83
|
|
96
84
|
context 'member found' do
|
@@ -121,13 +109,9 @@ shared_examples 'zip backend' do |backend_name|
|
|
121
109
|
end
|
122
110
|
end
|
123
111
|
|
124
|
-
|
125
|
-
it_behaves_like 'raises ArchiveNotFoundError', :extract_member, archive_member_files.first, 'destination'
|
126
|
-
end
|
112
|
+
it_behaves_like 'archive not found, raises ArchiveNotFoundError', :extract_member, archive_member_files.first, 'destination'
|
127
113
|
|
128
|
-
|
129
|
-
it 'raises ArchiveNotFoundError'
|
130
|
-
end
|
114
|
+
it_behaves_like 'archive is not a file, raises ArchiveNotFoundError', :extract_member, archive_member_files.first, 'destination'
|
131
115
|
|
132
116
|
context 'archive cannot be accessed due to permissions' do
|
133
117
|
it 'raises ArchiveNotAccessibleError'
|
@@ -142,10 +126,8 @@ shared_examples 'zip backend' do |backend_name|
|
|
142
126
|
end
|
143
127
|
end
|
144
128
|
end
|
145
|
-
end
|
146
129
|
|
147
|
-
|
148
|
-
context "backend: #{backend_name}" do
|
130
|
+
describe '#list_members' do
|
149
131
|
context 'file contains members' do
|
150
132
|
it 'returns array member file names' do
|
151
133
|
expect(subject.list_members).to eq(archive_member_names)
|
@@ -169,16 +151,15 @@ shared_examples 'zip backend' do |backend_name|
|
|
169
151
|
end
|
170
152
|
|
171
153
|
context 'contains no members, is empty archive' do
|
172
|
-
|
154
|
+
let(:filename) { empty_archive_fixture_filename }
|
155
|
+
it 'returns empty array' do
|
156
|
+
expect(subject.list_members).to eq( [ ] )
|
157
|
+
end
|
173
158
|
end
|
174
159
|
|
175
|
-
|
176
|
-
it_behaves_like 'raises ArchiveNotFoundError', :list_members
|
177
|
-
end
|
160
|
+
it_behaves_like 'archive not found, raises ArchiveNotFoundError', :list_members
|
178
161
|
|
179
|
-
|
180
|
-
it 'raises ArchiveNotFoundError'
|
181
|
-
end
|
162
|
+
it_behaves_like 'archive is not a file, raises ArchiveNotFoundError', :list_members
|
182
163
|
|
183
164
|
context 'archive cannot be accessed due to permissions' do
|
184
165
|
it 'raises ArchiveNotAccessibleError'
|
@@ -188,10 +169,8 @@ shared_examples 'zip backend' do |backend_name|
|
|
188
169
|
it_behaves_like 'raises InvalidArchiveError', :list_members
|
189
170
|
end
|
190
171
|
end
|
191
|
-
end
|
192
172
|
|
193
|
-
|
194
|
-
context "backend: #{backend_name}" do
|
173
|
+
describe '#member_exists?' do
|
195
174
|
context 'member is a file' do
|
196
175
|
it 'returns true if member exists' do
|
197
176
|
expect(subject.member_exists?(archive_member_files.first)).to be_truthy
|
@@ -208,13 +187,9 @@ shared_examples 'zip backend' do |backend_name|
|
|
208
187
|
expect(subject.member_exists?('does_not_exist')).to be_falsey
|
209
188
|
end
|
210
189
|
|
211
|
-
|
212
|
-
it_behaves_like 'raises ArchiveNotFoundError', :member_exists?, archive_member_files.first
|
213
|
-
end
|
190
|
+
it_behaves_like 'archive not found, raises ArchiveNotFoundError', :member_exists?, archive_member_files.first
|
214
191
|
|
215
|
-
|
216
|
-
it 'raises ArchiveNotFoundError'
|
217
|
-
end
|
192
|
+
it_behaves_like 'archive is not a file, raises ArchiveNotFoundError', :member_exists?, archive_member_files.first
|
218
193
|
|
219
194
|
context 'archive cannot be accessed due to permissions' do
|
220
195
|
it 'raises ArchiveNotAccessibleError'
|
@@ -224,10 +199,8 @@ shared_examples 'zip backend' do |backend_name|
|
|
224
199
|
it_behaves_like 'raises InvalidArchiveError', :member_exists?, archive_member_files.first
|
225
200
|
end
|
226
201
|
end
|
227
|
-
end
|
228
202
|
|
229
|
-
|
230
|
-
context "backend: #{backend_name}" do
|
203
|
+
describe '#write_member' do
|
231
204
|
after { FileUtils.rm(filename) if File.exists?(filename) }
|
232
205
|
|
233
206
|
let(:filename) { "/tmp/multizip_test.zip" }
|
@@ -236,7 +209,7 @@ shared_examples 'zip backend' do |backend_name|
|
|
236
209
|
|
237
210
|
context 'archive did not exist' do
|
238
211
|
before { expect(File.exists?(filename)).to be_falsey }
|
239
|
-
|
212
|
+
|
240
213
|
let!(:result) do
|
241
214
|
subject.write_member(member_file_name, member_file_contents)
|
242
215
|
end
|
@@ -331,10 +304,8 @@ shared_examples 'zip backend' do |backend_name|
|
|
331
304
|
it 'raises ArchiveInvalidError'
|
332
305
|
end
|
333
306
|
end
|
334
|
-
end
|
335
307
|
|
336
|
-
|
337
|
-
context "backend: #{backend_name}" do
|
308
|
+
describe '#remove_member' do
|
338
309
|
subject { MultiZip.new(temp_filename, :backend => backend_name) }
|
339
310
|
|
340
311
|
let(:temp_filename) { "/tmp/multizip_test.zip" }
|
@@ -351,7 +322,7 @@ shared_examples 'zip backend' do |backend_name|
|
|
351
322
|
MultiZip.new(temp_filename).member_exists?(member_file_name)
|
352
323
|
).to be_truthy
|
353
324
|
end
|
354
|
-
|
325
|
+
|
355
326
|
let!(:result) do
|
356
327
|
subject.remove_member(member_file_name)
|
357
328
|
end
|
@@ -379,9 +350,7 @@ shared_examples 'zip backend' do |backend_name|
|
|
379
350
|
end
|
380
351
|
end
|
381
352
|
|
382
|
-
|
383
|
-
it_behaves_like 'raises ArchiveNotFoundError', :remove_member, archive_member_files.first
|
384
|
-
end
|
353
|
+
it_behaves_like 'archive not found, raises ArchiveNotFoundError', :remove_member, archive_member_files.first
|
385
354
|
|
386
355
|
context 'archive is not a file' do
|
387
356
|
it 'raises ArchiveNotFoundError'
|
@@ -395,10 +364,8 @@ shared_examples 'zip backend' do |backend_name|
|
|
395
364
|
it 'raises ArchiveInvalidError'
|
396
365
|
end
|
397
366
|
end
|
398
|
-
end
|
399
367
|
|
400
|
-
|
401
|
-
context "backend: #{backend_name}" do
|
368
|
+
describe '#remove_members' do
|
402
369
|
subject { MultiZip.new(temp_filename, :backend => backend_name) }
|
403
370
|
|
404
371
|
let(:temp_filename) { "/tmp/multizip_test.zip" }
|
@@ -417,7 +384,7 @@ shared_examples 'zip backend' do |backend_name|
|
|
417
384
|
).to be_truthy
|
418
385
|
end
|
419
386
|
end
|
420
|
-
|
387
|
+
|
421
388
|
let!(:result) do
|
422
389
|
subject.remove_members(member_file_names)
|
423
390
|
end
|
@@ -447,9 +414,7 @@ shared_examples 'zip backend' do |backend_name|
|
|
447
414
|
end
|
448
415
|
end
|
449
416
|
|
450
|
-
|
451
|
-
it_behaves_like 'raises ArchiveNotFoundError', :remove_members, archive_member_files
|
452
|
-
end
|
417
|
+
it_behaves_like 'archive not found, raises ArchiveNotFoundError', :remove_members, archive_member_files
|
453
418
|
|
454
419
|
context 'archive is not a file' do
|
455
420
|
it 'raises ArchiveNotFoundError'
|
@@ -463,7 +428,7 @@ shared_examples 'zip backend' do |backend_name|
|
|
463
428
|
it 'raises ArchiveInvalidError'
|
464
429
|
end
|
465
430
|
end
|
466
|
-
end
|
431
|
+
end
|
467
432
|
end
|
468
433
|
|
469
434
|
shared_examples 'raises MemberNotFoundError' do |*args|
|
@@ -480,8 +445,22 @@ shared_examples 'raises InvalidArchiveError' do |*args|
|
|
480
445
|
end
|
481
446
|
|
482
447
|
shared_examples 'raises ArchiveNotFoundError' do |*args|
|
483
|
-
let(:filename) { 'doesnt_exist' }
|
484
448
|
it 'raises ArchiveNotFoundError' do
|
485
449
|
expect(lambda{ subject.send(args.shift, *args) }).to raise_error(MultiZip::ArchiveNotFoundError)
|
486
450
|
end
|
487
451
|
end
|
452
|
+
|
453
|
+
shared_examples 'archive not found, raises ArchiveNotFoundError' do |*args|
|
454
|
+
context 'archive not found' do
|
455
|
+
let(:filename) { 'doesnt_exist' }
|
456
|
+
it_behaves_like 'raises ArchiveNotFoundError', *args
|
457
|
+
end
|
458
|
+
end
|
459
|
+
|
460
|
+
shared_examples 'archive is not a file, raises ArchiveNotFoundError' do |*args|
|
461
|
+
context 'archive is not a file' do
|
462
|
+
let(:filename) { not_an_archive_fixture_filename }
|
463
|
+
it_behaves_like 'raises ArchiveNotFoundError', *args
|
464
|
+
end
|
465
|
+
end
|
466
|
+
|
Binary file
|
File without changes
|
data/spec/spec_helper.rb
CHANGED
@@ -2,8 +2,7 @@ require 'multi_zip'
|
|
2
2
|
|
3
3
|
# can't use pry on old rubies or on rubinius
|
4
4
|
if RUBY_VERSION.to_f >= 2.0 && RUBY_ENGINE == 'ruby'
|
5
|
-
require '
|
6
|
-
require 'pry-byebug'
|
5
|
+
require 'byebug'
|
7
6
|
end
|
8
7
|
|
9
8
|
RSpec.configure do |config|
|
@@ -29,12 +28,24 @@ RSpec.configure do |config|
|
|
29
28
|
Kernel.srand config.seed
|
30
29
|
end
|
31
30
|
|
31
|
+
def fixture_path(file)
|
32
|
+
['spec/fixtures/', file].join
|
33
|
+
end
|
34
|
+
|
32
35
|
def invalid_archive_fixture_filename
|
33
|
-
'
|
36
|
+
fixture_path('invalid.zip')
|
34
37
|
end
|
35
38
|
|
36
39
|
def archive_fixture_filename
|
37
|
-
'
|
40
|
+
fixture_path('test.zip')
|
41
|
+
end
|
42
|
+
|
43
|
+
def not_an_archive_fixture_filename
|
44
|
+
fixture_path('test')
|
45
|
+
end
|
46
|
+
|
47
|
+
def empty_archive_fixture_filename
|
48
|
+
fixture_path('empty.zip')
|
38
49
|
end
|
39
50
|
|
40
51
|
def archive_members
|
@@ -72,7 +83,7 @@ def test_with_rubyzip?
|
|
72
83
|
end
|
73
84
|
false
|
74
85
|
rescue Gem::LoadError
|
75
|
-
false
|
86
|
+
false
|
76
87
|
end
|
77
88
|
|
78
89
|
def test_with_zipruby?
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: multi_zip
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matthew Nielsen
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-04-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -44,14 +44,14 @@ dependencies:
|
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: 3.
|
47
|
+
version: 3.4.0
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: 3.
|
54
|
+
version: 3.4.0
|
55
55
|
description: Abstracts zipping and unzipping using whatever gems are installed using
|
56
56
|
one consistent API. Provides swappable zipping/unzipping backends so you're not
|
57
57
|
tied to just one gem. Supports rubyzip, archive-zip, zipruby and others.
|
@@ -70,6 +70,7 @@ files:
|
|
70
70
|
- LICENSE.txt
|
71
71
|
- README.md
|
72
72
|
- Rakefile
|
73
|
+
- TODO.md
|
73
74
|
- lib/multi_zip.rb
|
74
75
|
- lib/multi_zip/backend/archive_zip.rb
|
75
76
|
- lib/multi_zip/backend/rubyzip.rb
|
@@ -78,8 +79,10 @@ files:
|
|
78
79
|
- lib/multi_zip/version.rb
|
79
80
|
- multi_zip.gemspec
|
80
81
|
- spec/backend_shared_example.rb
|
82
|
+
- spec/fixtures/empty.zip
|
81
83
|
- spec/fixtures/invalid.zip
|
82
84
|
- spec/fixtures/test.zip
|
85
|
+
- spec/fixtures/test/.gitkeep
|
83
86
|
- spec/lib/multi_zip/backend/archive_zip_spec.rb
|
84
87
|
- spec/lib/multi_zip/backend/rubyzip_spec.rb
|
85
88
|
- spec/lib/multi_zip/backend/zipruby_spec.rb
|
@@ -111,8 +114,10 @@ specification_version: 4
|
|
111
114
|
summary: Abstracts zipping and unzipping using whatever gems are installed, automatically.
|
112
115
|
test_files:
|
113
116
|
- spec/backend_shared_example.rb
|
117
|
+
- spec/fixtures/empty.zip
|
114
118
|
- spec/fixtures/invalid.zip
|
115
119
|
- spec/fixtures/test.zip
|
120
|
+
- spec/fixtures/test/.gitkeep
|
116
121
|
- spec/lib/multi_zip/backend/archive_zip_spec.rb
|
117
122
|
- spec/lib/multi_zip/backend/rubyzip_spec.rb
|
118
123
|
- spec/lib/multi_zip/backend/zipruby_spec.rb
|