mds_file_utils 0.4.1 → 0.4.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +3 -3
- data/lib/mds_file_utils/zip_analyzer.rb +3 -11
- data/lib/mds_file_utils.rb +0 -1
- data/mds_file_utils.gemspec +18 -18
- data/spec/zip_analyzer_spec.rb +41 -25
- metadata +10 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f4922919722fa024374d42c8bc739b2ec80c8922c8047dc643675194fe7c7163
|
4
|
+
data.tar.gz: 59b410c799c42972ea3905c6bf8a0e4d16899b81f9a9ceeee0b3b27949d41da2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9dca16d1ebbf8ee0f64f667e067b3ef2fcd7cf8ae22414d869d3e54da58440ead5c5ca0e4cc86ca2e5d834dd9e7575fcaefe7ba2d599c1d1ecdfa63d3efceae0
|
7
|
+
data.tar.gz: 18a01149f20216ccaa8c743e5bf5dea3197d33c5d27668b9542293dc34b1bc3ca40c60065a605b5b5ac100986dbe432129b4cada3fbba6218f0af4266c8cf120
|
data/Gemfile
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
source "http://rubygems.org"
|
2
2
|
# Add dependencies required to use your gem here.
|
3
3
|
# Example:
|
4
|
-
gem
|
4
|
+
gem 'activesupport', '6.1.7.6'
|
5
5
|
gem "unzipMe", "~> 1.1.2"
|
6
|
-
gem '
|
6
|
+
gem 'zipruby', '~> 0.3.6'
|
7
7
|
# Add dependencies to develop your gem here.
|
8
8
|
# Include everything needed to run rake, tests, features, etc.
|
9
9
|
group :development do
|
10
|
-
gem "rspec"
|
10
|
+
gem "rspec", "~> 3.6"
|
11
11
|
gem "rdoc", "~> 4.1"
|
12
12
|
gem "bundler", "~> 2.4"
|
13
13
|
gem 'psych', '~> 5.1'
|
@@ -1,4 +1,3 @@
|
|
1
|
-
require 'zip'
|
2
1
|
module MdsFileUtils
|
3
2
|
|
4
3
|
class ZipAnalyzer
|
@@ -14,16 +13,10 @@ module MdsFileUtils
|
|
14
13
|
end
|
15
14
|
|
16
15
|
def valid_zip?
|
17
|
-
return false if @path.blank?
|
16
|
+
return false if @path.blank?
|
17
|
+
return false unless File.exist?(@path)
|
18
18
|
return false unless has_valid_extension?
|
19
|
-
|
20
|
-
begin
|
21
|
-
Zip::File.open(@path) { |zip_file| }
|
22
|
-
|
23
|
-
true # The zip file is valid
|
24
|
-
rescue Zip::Error => e
|
25
|
-
false # The zip file is not valid
|
26
|
-
end
|
19
|
+
UnzipmeValidator.new(@path).valid_zip?
|
27
20
|
end
|
28
21
|
|
29
22
|
def has_valid_extension?
|
@@ -33,7 +26,6 @@ module MdsFileUtils
|
|
33
26
|
|
34
27
|
def is_composite?
|
35
28
|
return false unless valid_zip?
|
36
|
-
puts "file_list: #{file_list}"
|
37
29
|
file_list.count { | file | file =~ EXTENSION_REGEX } > 0
|
38
30
|
end
|
39
31
|
|
data/lib/mds_file_utils.rb
CHANGED
data/mds_file_utils.gemspec
CHANGED
@@ -6,12 +6,12 @@
|
|
6
6
|
|
7
7
|
Gem::Specification.new do |s|
|
8
8
|
s.name = "mds_file_utils"
|
9
|
-
s.version = "0.4.
|
9
|
+
s.version = "0.4.2"
|
10
10
|
|
11
11
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
12
12
|
s.require_paths = ["lib"]
|
13
13
|
s.authors = ["Dave", "Kendra"]
|
14
|
-
s.date = "
|
14
|
+
s.date = "2017-07-18"
|
15
15
|
s.description = "A set of useful MDS file utilities."
|
16
16
|
s.email = "kmulvey@providigm.com"
|
17
17
|
s.extra_rdoc_files = [
|
@@ -37,34 +37,34 @@ Gem::Specification.new do |s|
|
|
37
37
|
]
|
38
38
|
s.homepage = "http://github.com/GitHubAdmin/mds_file_utils"
|
39
39
|
s.licenses = ["MIT"]
|
40
|
-
s.rubygems_version = "
|
40
|
+
s.rubygems_version = "2.4.8"
|
41
41
|
s.summary = "A collection of MDS file utilities."
|
42
42
|
|
43
43
|
if s.respond_to? :specification_version then
|
44
44
|
s.specification_version = 4
|
45
45
|
|
46
46
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
47
|
-
s.add_runtime_dependency(%q<activesupport
|
47
|
+
s.add_runtime_dependency(%q<activesupport>, ["6.1.7.6"])
|
48
48
|
s.add_runtime_dependency(%q<unzipMe>, ["~> 1.1.2"])
|
49
|
-
s.add_development_dependency(%q<rspec
|
50
|
-
s.add_development_dependency(%q<rdoc
|
51
|
-
s.add_development_dependency(%q<bundler
|
52
|
-
s.add_development_dependency(%q<jeweler
|
49
|
+
s.add_development_dependency(%q<rspec>, ["~> 3.6"])
|
50
|
+
s.add_development_dependency(%q<rdoc>, ["~> 4.1"])
|
51
|
+
s.add_development_dependency(%q<bundler>, ["~> 2.4"])
|
52
|
+
s.add_development_dependency(%q<jeweler>, ["~> 2.3"])
|
53
53
|
else
|
54
|
-
s.add_dependency(%q<activesupport
|
54
|
+
s.add_dependency(%q<activesupport>, ["6.1.7.6"])
|
55
55
|
s.add_dependency(%q<unzipMe>, ["~> 1.1.2"])
|
56
|
-
s.add_dependency(%q<rspec
|
57
|
-
s.add_dependency(%q<rdoc
|
58
|
-
s.add_dependency(%q<bundler
|
59
|
-
s.add_dependency(%q<jeweler
|
56
|
+
s.add_dependency(%q<rspec>, ["~> 3.6"])
|
57
|
+
s.add_dependency(%q<rdoc>, ["~> 4.1"])
|
58
|
+
s.add_dependency(%q<bundler>, ["~> 2.4"])
|
59
|
+
s.add_dependency(%q<jeweler>, ["~> 2.3"])
|
60
60
|
end
|
61
61
|
else
|
62
|
-
s.add_dependency(%q<activesupport>, ["
|
62
|
+
s.add_dependency(%q<activesupport>, ["6.1.7.6"])
|
63
63
|
s.add_dependency(%q<unzipMe>, ["~> 1.1.2"])
|
64
|
-
s.add_dependency(%q<rspec
|
65
|
-
s.add_dependency(%q<rdoc
|
66
|
-
s.add_dependency(%q<bundler
|
67
|
-
s.add_dependency(%q<jeweler
|
64
|
+
s.add_dependency(%q<rspec>, ["~> 3.6"])
|
65
|
+
s.add_dependency(%q<rdoc>, ["~> 4.1"])
|
66
|
+
s.add_dependency(%q<bundler>, ["~> 2.4"])
|
67
|
+
s.add_dependency(%q<jeweler>, ["~> 2.3"])
|
68
68
|
end
|
69
69
|
end
|
70
70
|
|
data/spec/zip_analyzer_spec.rb
CHANGED
@@ -1,4 +1,6 @@
|
|
1
1
|
require 'spec_helper'
|
2
|
+
require 'zipruby'
|
3
|
+
|
2
4
|
|
3
5
|
describe MdsFileUtils::ZipAnalyzer do
|
4
6
|
|
@@ -57,35 +59,38 @@ describe MdsFileUtils::ZipAnalyzer do
|
|
57
59
|
it "should respond with true if asked if a valid zip file has an extension of '.zip'" do
|
58
60
|
@file_to_test = File.join('/tmp', 'file_to_test.zip')
|
59
61
|
contained_file = File.join('/tmp', 'contained_file')
|
60
|
-
|
61
|
-
# Create the contained file
|
62
62
|
File.open(contained_file, 'w') { |f| f.puts "Hello" }
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
zip_file.add('contained_file', contained_file)
|
63
|
+
|
64
|
+
Zip::Archive.open(@file_to_test, Zip::CREATE) do |archive|
|
65
|
+
archive.add_file('file.txt', contained_file)
|
67
66
|
end
|
67
|
+
|
68
|
+
# Optionally, remove the contained file after creating the ZIP.
|
69
|
+
FileUtils.rm contained_file
|
70
|
+
|
68
71
|
|
69
72
|
za = MdsFileUtils::ZipAnalyzer.new(@file_to_test)
|
70
73
|
|
71
74
|
za.valid_zip?.should be_truthy
|
72
|
-
|
73
|
-
|
74
75
|
end
|
76
|
+
|
75
77
|
|
76
|
-
it "should respond with true if asked if a valid zip file has an extension of '.
|
77
|
-
@file_to_test = File.join('/tmp', 'file_to_test.zip')
|
78
|
-
contained_file = File.join('/tmp', 'contained_file')
|
78
|
+
it "should respond with true if asked if a valid zip file has an extension of '.zip'" do
|
79
|
+
@file_to_test = File.join('/tmp', 'file_to_test.zip') # Use .zip extension for the ZIP file
|
80
|
+
contained_file = File.join('/tmp', 'contained_file.txt')
|
79
81
|
|
80
|
-
# Create the contained file
|
81
82
|
File.open(contained_file, 'w') { |f| f.puts "Hello" }
|
82
83
|
|
83
|
-
# Create
|
84
|
-
|
85
|
-
|
84
|
+
# Create a new ZIP file
|
85
|
+
Zip::Archive.open(@file_to_test, Zip::CREATE) do |archive|
|
86
|
+
entry = archive.add_file('file.txt', contained_file) # Add the contained file to the ZIP archive
|
86
87
|
end
|
87
88
|
|
89
|
+
# Optionally, remove the contained file after creating the ZIP.
|
90
|
+
FileUtils.rm contained_file
|
91
|
+
|
88
92
|
za = MdsFileUtils::ZipAnalyzer.new(@file_to_test)
|
93
|
+
|
89
94
|
|
90
95
|
za.valid_zip?.should be_truthy
|
91
96
|
end
|
@@ -102,17 +107,28 @@ describe MdsFileUtils::ZipAnalyzer do
|
|
102
107
|
|
103
108
|
it "should respond with true when asked if the file composite for a zip that contains nothing but files with a zip extension" do
|
104
109
|
@file_to_test = File.join('/tmp', 'file_to_test.zip')
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
110
|
+
|
111
|
+
# Create the ZIP files to go into the zip file
|
112
|
+
contained_paths = (1..2).map { |idx| File.join('/tmp', "contained_#{idx}.zip") }
|
113
|
+
contained_paths.each do |path|
|
114
|
+
# Create a dummy text file in /tmp directory
|
115
|
+
dummy_file_path = File.join('/tmp', 'dummy.txt')
|
116
|
+
File.open(dummy_file_path, 'w') { |f| f.puts "Hello, dummy!" }
|
117
|
+
|
118
|
+
# Create a new ZIP file containing the dummy.txt file
|
119
|
+
Zip::Archive.open(path, Zip::CREATE) do |archive|
|
120
|
+
entry = archive.add_file("dummy.txt", dummy_file_path)
|
113
121
|
end
|
114
|
-
|
115
|
-
|
122
|
+
end
|
123
|
+
|
124
|
+
# Create a new ZIP file containing only ZIP files
|
125
|
+
Zip::Archive.open(@file_to_test, Zip::CREATE) do |archive|
|
126
|
+
contained_paths.each do |path|
|
127
|
+
entry = archive.add_file(File.basename(path), path) # Add the contained ZIP files to the ZIP archive
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
za = MdsFileUtils::ZipAnalyzer.new(@file_to_test)
|
116
132
|
|
117
133
|
za.is_composite?.should be_truthy
|
118
134
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mds_file_utils
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dave
|
@@ -9,22 +9,22 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2017-07-18 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|
16
16
|
requirement: !ruby/object:Gem::Requirement
|
17
17
|
requirements:
|
18
|
-
- -
|
18
|
+
- - '='
|
19
19
|
- !ruby/object:Gem::Version
|
20
|
-
version:
|
20
|
+
version: 6.1.7.6
|
21
21
|
type: :runtime
|
22
22
|
prerelease: false
|
23
23
|
version_requirements: !ruby/object:Gem::Requirement
|
24
24
|
requirements:
|
25
|
-
- -
|
25
|
+
- - '='
|
26
26
|
- !ruby/object:Gem::Version
|
27
|
-
version:
|
27
|
+
version: 6.1.7.6
|
28
28
|
- !ruby/object:Gem::Dependency
|
29
29
|
name: unzipMe
|
30
30
|
requirement: !ruby/object:Gem::Requirement
|
@@ -43,16 +43,16 @@ dependencies:
|
|
43
43
|
name: rspec
|
44
44
|
requirement: !ruby/object:Gem::Requirement
|
45
45
|
requirements:
|
46
|
-
- - "
|
46
|
+
- - "~>"
|
47
47
|
- !ruby/object:Gem::Version
|
48
|
-
version: '
|
48
|
+
version: '3.6'
|
49
49
|
type: :development
|
50
50
|
prerelease: false
|
51
51
|
version_requirements: !ruby/object:Gem::Requirement
|
52
52
|
requirements:
|
53
|
-
- - "
|
53
|
+
- - "~>"
|
54
54
|
- !ruby/object:Gem::Version
|
55
|
-
version: '
|
55
|
+
version: '3.6'
|
56
56
|
- !ruby/object:Gem::Dependency
|
57
57
|
name: rdoc
|
58
58
|
requirement: !ruby/object:Gem::Requirement
|