unzipMe 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: f7c001780b6d928d8e6d0ea62b3dba66ae111de6
4
+ data.tar.gz: 3992d30072b3d528fb33fd83903d12e71cea2835
5
+ SHA512:
6
+ metadata.gz: b172b489fb2b84de788f045bb1b85215eeb4dff273100fedab6b47cfe53fee75fd6b46f52ef3f2e5c84a02e03c03f586fb91d4eb3fe19a875251df27302e953a
7
+ data.tar.gz: 2100504cdd263df54ace40facf3daad6113c706b1eec041f55460775645875d6a4ef65c11d9b540d67307f3e9d857ea5ed4f127c4d5233406409dfd3b87c9f70
data/Gemfile CHANGED
@@ -6,8 +6,8 @@ source "http://rubygems.org"
6
6
  # Add dependencies to develop your gem here.
7
7
  # Include everything needed to run rake, tests, features, etc.
8
8
  group :development do
9
- gem "rspec", ">= 2.8.0"
10
- gem "rdoc", ">= 3.12"
9
+ gem "rspec", "~> 2.14"
10
+ gem "rdoc", "~> 4.1"
11
11
  gem "bundler", ">= 1.0.0"
12
12
  gem "jeweler", "~> 1.8.4"
13
13
  #gem "rcov", ">= 0"
@@ -1,25 +1,54 @@
1
1
  GEM
2
2
  remote: http://rubygems.org/
3
3
  specs:
4
- diff-lcs (1.1.3)
5
- git (1.2.5)
6
- jeweler (1.8.4)
4
+ addressable (2.3.6)
5
+ builder (3.2.2)
6
+ diff-lcs (1.2.5)
7
+ faraday (0.8.9)
8
+ multipart-post (~> 1.2.0)
9
+ git (1.2.8)
10
+ github_api (0.10.1)
11
+ addressable
12
+ faraday (~> 0.8.1)
13
+ hashie (>= 1.2)
14
+ multi_json (~> 1.4)
15
+ nokogiri (~> 1.5.2)
16
+ oauth2
17
+ hashie (3.2.0)
18
+ highline (1.6.21)
19
+ jeweler (1.8.8)
20
+ builder
7
21
  bundler (~> 1.0)
8
22
  git (>= 1.2.5)
23
+ github_api (= 0.10.1)
24
+ highline (>= 1.6.15)
25
+ nokogiri (= 1.5.10)
9
26
  rake
10
27
  rdoc
11
- json (1.7.5)
12
- rake (10.0.2)
13
- rdoc (3.12)
28
+ json (1.8.1)
29
+ jwt (1.0.0)
30
+ multi_json (1.10.1)
31
+ multi_xml (0.5.5)
32
+ multipart-post (1.2.0)
33
+ nokogiri (1.5.10)
34
+ oauth2 (1.0.0)
35
+ faraday (>= 0.8, < 0.10)
36
+ jwt (~> 1.0)
37
+ multi_json (~> 1.3)
38
+ multi_xml (~> 0.5)
39
+ rack (~> 1.2)
40
+ rack (1.5.2)
41
+ rake (10.3.2)
42
+ rdoc (4.1.1)
14
43
  json (~> 1.4)
15
- rspec (2.12.0)
16
- rspec-core (~> 2.12.0)
17
- rspec-expectations (~> 2.12.0)
18
- rspec-mocks (~> 2.12.0)
19
- rspec-core (2.12.0)
20
- rspec-expectations (2.12.0)
21
- diff-lcs (~> 1.1.3)
22
- rspec-mocks (2.12.0)
44
+ rspec (2.99.0)
45
+ rspec-core (~> 2.99.0)
46
+ rspec-expectations (~> 2.99.0)
47
+ rspec-mocks (~> 2.99.0)
48
+ rspec-core (2.99.1)
49
+ rspec-expectations (2.99.2)
50
+ diff-lcs (>= 1.1.3, < 2.0)
51
+ rspec-mocks (2.99.2)
23
52
 
24
53
  PLATFORMS
25
54
  ruby
@@ -27,5 +56,5 @@ PLATFORMS
27
56
  DEPENDENCIES
28
57
  bundler (>= 1.0.0)
29
58
  jeweler (~> 1.8.4)
30
- rdoc (>= 3.12)
31
- rspec (>= 2.8.0)
59
+ rdoc (~> 4.1)
60
+ rspec (~> 2.14)
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.0.0
1
+ 1.1.0
@@ -0,0 +1,17 @@
1
+ #!/usr/bin/env ruby
2
+ require 'unzipMe'
3
+ #
4
+ # A test program to determine the feasibility of recursively unzipping
5
+ # a ZIP file. That is, if the zip contains zips, the resulting extraction
6
+ # should explode the internal zips as well as the outer one.
7
+ #
8
+ FILE = ARGV.last
9
+
10
+ raise "Must specify zip file to unpack!" if FILE.nil?
11
+ raise "The specified file must exist: #{FILE}" unless File.exists?(FILE)
12
+
13
+ UNZIP_DIR = File.join(File.dirname(FILE), "extracted_files")
14
+
15
+ unzipper = RecursiveUnzipper.new(FILE)
16
+ unzipper.extract_to(UNZIP_DIR)
17
+ puts unzipper.exceptions.inspect unless unzipper.exceptions.empty?
@@ -1,3 +1,5 @@
1
+ require 'fileutils'
1
2
  require 'unzip_me/unzipme_unzipper'
2
3
  require 'unzip_me/unzipme_exception'
3
4
  require 'unzip_me/unzipme_validator'
5
+ require 'unzip_me/recursive_unzipper'
@@ -0,0 +1,47 @@
1
+ class RecursiveUnzipper
2
+ attr_reader :zip_path, :exceptions
3
+
4
+ def initialize(zip_path)
5
+ @zip_path = zip_path
6
+ @exceptions = {}
7
+ end
8
+
9
+ def extract_to(extract_to_path)
10
+ UnzipmeUnzipper.new(zip_path, { extract_to: extract_to_path }).unzip
11
+ scan_and_unzip_dir(extract_to_path)
12
+ end
13
+
14
+ private
15
+
16
+ def scan_and_unzip_dir(dir)
17
+ unzip_all_zips_in_directory(dir)
18
+
19
+ # Are there any sub-directories in this directory?
20
+ Dir.foreach(dir) do |entry|
21
+ next if [ '.', '..' ].include?(entry)
22
+ path = File.join(dir, entry)
23
+ scan_and_unzip_dir(path) if File.directory?(path)
24
+ end
25
+ end
26
+
27
+ def unzip_all_zips_in_directory(dir)
28
+ # Are there any zip files in this directory? If so,
29
+ # extract the contents to a subdirectory of the
30
+ # current directory
31
+ Dir.glob(File.join(dir, "*.zip"), File::FNM_CASEFOLD) do | zip_file_name |
32
+ # Create a directory in which to place the contents of the zip
33
+ contents_dir = File.join(dir, "#{File.basename(zip_file_name)}.contents")
34
+ FileUtils.mkdir_p(contents_dir)
35
+ begin
36
+ UnzipmeUnzipper.new(zip_file_name, { extract_to: contents_dir }).unzip
37
+ rescue => ex
38
+ FileUtils.rm_rf(contents_dir)
39
+ exceptions[zip_file_name] = ex
40
+ ensure
41
+ File.delete(zip_file_name)
42
+ end
43
+ end
44
+ end
45
+
46
+ end
47
+
@@ -0,0 +1,100 @@
1
+ require 'spec_helper'
2
+
3
+ describe RecursiveUnzipper do
4
+ let(:cut) { RecursiveUnzipper.new('/tmp/file/something.zip') }
5
+ let(:dir) { '/tmp/recursive_unwrapper' }
6
+
7
+ context '#extract_to' do
8
+
9
+ it "will unzip the archive and recursively extract all zips" do
10
+ m_unzipper = double('UnzipmeUnzipper')
11
+ m_unzipper.should_receive(:unzip)
12
+
13
+ cut.should_receive(:scan_and_unzip_dir).with('/tmp/somewhere')
14
+
15
+ UnzipmeUnzipper.should_receive(:new).with('/tmp/file/something.zip', { extract_to: '/tmp/somewhere' }).and_return(m_unzipper)
16
+
17
+ cut.extract_to('/tmp/somewhere')
18
+ end
19
+
20
+ end
21
+
22
+ context '#unzip_all_zips_in_directory' do
23
+
24
+ it 'should do nothing if no zip found in the specified directory' do
25
+ FileUtils.mkdir_p(dir)
26
+
27
+ begin
28
+ cut.send(:unzip_all_zips_in_directory, dir)
29
+ ensure
30
+ FileUtils.rm_rf(dir)
31
+ end
32
+
33
+ end
34
+
35
+ it "should unpack the zip if found in directory" do
36
+ FileUtils.mkdir_p(dir)
37
+
38
+ %x{ touch #{File.join(dir, "something.zip") } }
39
+
40
+ m_unzipper = double('UnzipmeUnzipper')
41
+ m_unzipper.should_receive(:unzip)
42
+ zip_path = File.join(dir, 'something.zip')
43
+ UnzipmeUnzipper.should_receive(:new).with(zip_path, { extract_to: '/tmp/recursive_unwrapper/something.zip.contents' }).and_return(m_unzipper)
44
+
45
+ begin
46
+ cut.send(:unzip_all_zips_in_directory, dir)
47
+
48
+ # The contents directory should be created
49
+ contents_dir = File.join(dir, 'something.zip.contents')
50
+ expect(File.exists?(contents_dir)).to be_true
51
+ expect(File.directory?(contents_dir)).to be_true
52
+
53
+ # The zip file should be deleted
54
+ expect(File.exists?(zip_path)).to be_false
55
+ ensure
56
+ FileUtils.rm_rf(dir)
57
+ end
58
+
59
+ end
60
+
61
+ it "should catch exception, record and remove the zip file" do
62
+ FileUtils.mkdir_p(dir)
63
+
64
+ %x{ touch #{File.join(dir, "something.zip") } }
65
+
66
+ m_unzipper = double('UnzipmeUnzipper')
67
+ m_unzipper.should_receive(:unzip).and_raise(StandardError)
68
+ zip_path = File.join(dir, 'something.zip')
69
+ UnzipmeUnzipper.should_receive(:new).with(zip_path, { extract_to: '/tmp/recursive_unwrapper/something.zip.contents' }).and_return(m_unzipper)
70
+
71
+ begin
72
+ cut.send(:unzip_all_zips_in_directory, dir)
73
+
74
+ # The contents directory should be removed
75
+ contents_dir = File.join(dir, 'something.zip.contents')
76
+ expect(File.exists?(contents_dir)).to be_false
77
+
78
+ # The zip file should be deleted
79
+ expect(File.exists?(zip_path)).to be_false
80
+ expect(cut.exceptions.count).to be(1)
81
+ ensure
82
+ FileUtils.rm_rf(dir)
83
+ end
84
+
85
+ end
86
+ end
87
+
88
+ context '#scan_and_unzip_dir' do
89
+
90
+ it "should just unzip all zip in dir if no other files in directory" do
91
+ FileUtils.mkdir_p(dir)
92
+
93
+ cut.should_receive(:unzip_all_zips_in_directory).with(dir)
94
+
95
+ cut.send(:scan_and_unzip_dir, dir)
96
+ end
97
+
98
+ end
99
+
100
+ end
@@ -0,0 +1,63 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = "unzipMe"
8
+ s.version = "0.0.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Kendra Lawlor"]
12
+ s.date = "2012-12-07"
13
+ s.description = "using system unzip command and then 7zip as failover"
14
+ s.email = "lawlorkendra@gmail.com"
15
+ s.extra_rdoc_files = [
16
+ "LICENSE.txt",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ ".rspec",
22
+ "Gemfile",
23
+ "Gemfile.lock",
24
+ "LICENSE.txt",
25
+ "README.rdoc",
26
+ "Rakefile",
27
+ "VERSION",
28
+ "lib/unzipMe.rb",
29
+ "lib/unzip_me/unzipme_exception.rb",
30
+ "lib/unzip_me/unzipme_unzipper.rb",
31
+ "lib/unzip_me/unzipme_validator.rb",
32
+ "spec/spec_helper.rb",
33
+ "spec/unzipme_unzipper_spec.rb",
34
+ "spec/unzipme_validator_spec.rb"
35
+ ]
36
+ s.homepage = "http://github.com/kendra/unzipMe"
37
+ s.licenses = ["MIT"]
38
+ s.require_paths = ["lib"]
39
+ s.rubygems_version = "1.8.23"
40
+ s.summary = "using system unzip command and then 7zip as failover"
41
+
42
+ if s.respond_to? :specification_version then
43
+ s.specification_version = 3
44
+
45
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
46
+ s.add_development_dependency(%q<rspec>, [">= 2.8.0"])
47
+ s.add_development_dependency(%q<rdoc>, [">= 3.12"])
48
+ s.add_development_dependency(%q<bundler>, [">= 1.0.0"])
49
+ s.add_development_dependency(%q<jeweler>, ["~> 1.8.4"])
50
+ else
51
+ s.add_dependency(%q<rspec>, [">= 2.8.0"])
52
+ s.add_dependency(%q<rdoc>, [">= 3.12"])
53
+ s.add_dependency(%q<bundler>, [">= 1.0.0"])
54
+ s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
55
+ end
56
+ else
57
+ s.add_dependency(%q<rspec>, [">= 2.8.0"])
58
+ s.add_dependency(%q<rdoc>, [">= 3.12"])
59
+ s.add_dependency(%q<bundler>, [">= 1.0.0"])
60
+ s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
61
+ end
62
+ end
63
+
metadata CHANGED
@@ -1,112 +1,121 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: unzipMe
3
- version: !ruby/object:Gem::Version
4
- prerelease:
5
- version: 1.0.0
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.1.0
6
5
  platform: ruby
7
- authors:
6
+ authors:
8
7
  - Kendra Lawlor
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
-
13
- date: 2012-12-07 00:00:00 Z
14
- dependencies:
15
- - !ruby/object:Gem::Dependency
11
+ date: 2014-08-11 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
16
14
  name: rspec
17
- prerelease: false
18
- requirement: &id001 !ruby/object:Gem::Requirement
19
- none: false
20
- requirements:
21
- - - ">="
22
- - !ruby/object:Gem::Version
23
- version: 2.8.0
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.14'
24
20
  type: :development
25
- version_requirements: *id001
26
- - !ruby/object:Gem::Dependency
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.14'
27
+ - !ruby/object:Gem::Dependency
27
28
  name: rdoc
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '4.1'
34
+ type: :development
28
35
  prerelease: false
29
- requirement: &id002 !ruby/object:Gem::Requirement
30
- none: false
31
- requirements:
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '4.1'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
32
45
  - - ">="
33
- - !ruby/object:Gem::Version
34
- version: "3.12"
46
+ - !ruby/object:Gem::Version
47
+ version: 1.0.0
35
48
  type: :development
36
- version_requirements: *id002
37
- - !ruby/object:Gem::Dependency
38
- name: bundler
39
49
  prerelease: false
40
- requirement: &id003 !ruby/object:Gem::Requirement
41
- none: false
42
- requirements:
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
43
52
  - - ">="
44
- - !ruby/object:Gem::Version
53
+ - !ruby/object:Gem::Version
45
54
  version: 1.0.0
46
- type: :development
47
- version_requirements: *id003
48
- - !ruby/object:Gem::Dependency
55
+ - !ruby/object:Gem::Dependency
49
56
  name: jeweler
50
- prerelease: false
51
- requirement: &id004 !ruby/object:Gem::Requirement
52
- none: false
53
- requirements:
54
- - - ~>
55
- - !ruby/object:Gem::Version
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
56
61
  version: 1.8.4
57
62
  type: :development
58
- version_requirements: *id004
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 1.8.4
59
69
  description: using system unzip command and then 7zip as failover
60
70
  email: lawlorkendra@gmail.com
61
- executables: []
62
-
71
+ executables:
72
+ - recursive_unzip.rb
63
73
  extensions: []
64
-
65
- extra_rdoc_files:
74
+ extra_rdoc_files:
66
75
  - LICENSE.txt
67
76
  - README.rdoc
68
- files:
69
- - .document
70
- - .rspec
77
+ files:
78
+ - ".document"
79
+ - ".rspec"
71
80
  - Gemfile
72
81
  - Gemfile.lock
73
82
  - LICENSE.txt
74
83
  - README.rdoc
75
84
  - Rakefile
76
85
  - VERSION
86
+ - bin/recursive_unzip.rb
77
87
  - lib/unzipMe.rb
88
+ - lib/unzip_me/recursive_unzipper.rb
78
89
  - lib/unzip_me/unzipme_exception.rb
79
90
  - lib/unzip_me/unzipme_unzipper.rb
80
91
  - lib/unzip_me/unzipme_validator.rb
92
+ - spec/recursive_unzipper_spec.rb
81
93
  - spec/spec_helper.rb
82
94
  - spec/unzipme_unzipper_spec.rb
83
95
  - spec/unzipme_validator_spec.rb
96
+ - unzipMe.gemspec
84
97
  homepage: http://github.com/kendra/unzipMe
85
- licenses:
98
+ licenses:
86
99
  - MIT
100
+ metadata: {}
87
101
  post_install_message:
88
102
  rdoc_options: []
89
-
90
- require_paths:
103
+ require_paths:
91
104
  - lib
92
- required_ruby_version: !ruby/object:Gem::Requirement
93
- none: false
94
- requirements:
105
+ required_ruby_version: !ruby/object:Gem::Requirement
106
+ requirements:
95
107
  - - ">="
96
- - !ruby/object:Gem::Version
97
- version: "0"
98
- required_rubygems_version: !ruby/object:Gem::Requirement
99
- none: false
100
- requirements:
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ required_rubygems_version: !ruby/object:Gem::Requirement
111
+ requirements:
101
112
  - - ">="
102
- - !ruby/object:Gem::Version
103
- version: "0"
113
+ - !ruby/object:Gem::Version
114
+ version: '0'
104
115
  requirements: []
105
-
106
116
  rubyforge_project:
107
- rubygems_version: 1.8.23
117
+ rubygems_version: 2.2.2
108
118
  signing_key:
109
- specification_version: 3
119
+ specification_version: 4
110
120
  summary: using system unzip command and then 7zip as failover
111
121
  test_files: []
112
-