mundane 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/mundane.rb +0 -1
- data/lib/mundane/algos/zips_to_files.rb +17 -8
- data/lib/mundane/version.rb +1 -1
- data/spec/spec_helper.rb +7 -1
- data/spec/unit/mundane_spec.rb +15 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a2f884eb09a064e4a09eeeba3ffaf1521a9faedc
|
4
|
+
data.tar.gz: 5526ff7375980336cb4c36516304dec0415bf225
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3ab03630bc0aa83ec2b3b163f048ad359f3023b79b8fd5a78b225eef6774b17360274dfb5a11653da5879cbcef18e0d41173de866f60e513036f308b3fef4b59
|
7
|
+
data.tar.gz: f215cd036269ceae089f114238e4320e979db4992b8df529572ad716fa90d6d06b8482544f75f53682e2a7409dc8e431f6f2c5eb00fc8a5b6ff85bdc5468a75e
|
data/lib/mundane.rb
CHANGED
@@ -16,25 +16,34 @@ module Mundane
|
|
16
16
|
|
17
17
|
def self.decompress_files_and_dump_them_to_out(files)
|
18
18
|
incomplete_extractions = 0
|
19
|
+
all_files_were_archives = true
|
19
20
|
|
20
21
|
# decompress each file in the list
|
21
22
|
files.each do |zip|
|
22
23
|
# TODO: next if zip.extension != 'zip'
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
24
|
+
begin
|
25
|
+
Zip::File.open(zip) do |archive|
|
26
|
+
archive.each do |f|
|
27
|
+
output_path = "out/#{f.name}"
|
28
|
+
if File.exists? output_path # don't auto-overwrite anything...
|
29
|
+
puts "#{output_path} ALREADY EXISTED, SKIPPING FILE."
|
30
|
+
incomplete_extractions += 1
|
31
|
+
next
|
32
|
+
end
|
33
|
+
|
34
|
+
FileUtils.mkdir_p File.dirname(output_path)
|
35
|
+
f.extract output_path
|
30
36
|
end
|
31
|
-
f.extract output_path
|
32
37
|
end
|
38
|
+
rescue
|
39
|
+
# skip the file if it can't be opened like a zip
|
40
|
+
all_files_were_archives = false
|
33
41
|
end
|
34
42
|
|
35
43
|
end
|
36
44
|
|
37
45
|
puts "\nOperation terminated, there were #{incomplete_extractions} incomplete extractions." if incomplete_extractions > 0
|
46
|
+
puts "Not all files were valid archives" unless all_files_were_archives
|
38
47
|
end
|
39
48
|
|
40
49
|
end
|
data/lib/mundane/version.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
@@ -23,7 +23,13 @@ def drop_dummy_zip_file
|
|
23
23
|
# This string was coppied from a hex editor (bless) on linux
|
24
24
|
byte_array_of_zip_file = "50 4B 03 04 0A 03 00 00 00 00 9A 85 4C 43 05 40 6D 5B 08 00 00 00 08 00 00 00 01 00 00 00 61 68 65 6C 6C 6F 20 61 0A 50 4B 03 04 0A 03 00 00 00 00 B8 85 4C 43 C6 13 40 70 08 00 00 00 08 00 00 00 01 00 00 00 62 68 65 6C 6C 6F 20 62 0A 50 4B 01 02 3F 03 0A 03 00 00 00 00 9A 85 4C 43 05 40 6D 5B 08 00 00 00 08 00 00 00 01 00 00 00 00 00 00 00 00 00 20 80 A4 81 00 00 00 00 61 50 4B 01 02 3F 03 0A 03 00 00 00 00 B8 85 4C 43 C6 13 40 70 08 00 00 00 08 00 00 00 01 00 00 00 00 00 00 00 00 00 20 80 A4 81 27 00 00 00 62 50 4B 05 06 00 00 00 00 02 00 02 00 5E 00 00 00 4E 00 00 00 00 00"
|
25
25
|
bin_format = byte_array_of_zip_file.split.map {|s| s.to_i(16).chr}
|
26
|
-
File.binwrite("
|
26
|
+
File.binwrite("embedded.zip", bin_format.join)
|
27
|
+
end
|
28
|
+
|
29
|
+
def drop_dummy_zip_file_with_folders
|
30
|
+
byte_array_of_zip_file = "50 4B 03 04 0A 03 00 00 00 00 EA 72 4D 43 C6 13 40 70 08 00 00 00 08 00 00 00 05 00 00 00 62 2E 74 78 74 68 65 6C 6C 6F 20 62 0A 50 4B 03 04 14 03 00 00 00 00 80 72 4D 43 00 00 00 00 00 00 00 00 00 00 00 00 09 00 00 00 66 6F 6C 64 65 72 5F 61 2F 50 4B 03 04 0A 03 00 00 00 00 80 72 4D 43 05 40 6D 5B 08 00 00 00 08 00 00 00 0E 00 00 00 66 6F 6C 64 65 72 5F 61 2F 61 2E 74 78 74 68 65 6C 6C 6F 20 61 0A 50 4B 01 02 3F 03 0A 03 00 00 00 00 EA 72 4D 43 C6 13 40 70 08 00 00 00 08 00 00 00 05 00 00 00 00 00 00 00 00 00 20 80 A4 81 00 00 00 00 62 2E 74 78 74 50 4B 01 02 3F 03 14 03 00 00 00 00 80 72 4D 43 00 00 00 00 00 00 00 00 00 00 00 00 09 00 00 00 00 00 00 00 00 00 10 80 ED 41 2B 00 00 00 66 6F 6C 64 65 72 5F 61 2F 50 4B 01 02 3F 03 0A 03 00 00 00 00 80 72 4D 43 05 40 6D 5B 08 00 00 00 08 00 00 00 0E 00 00 00 00 00 00 00 00 00 20 80 A4 81 52 00 00 00 66 6F 6C 64 65 72 5F 61 2F 61 2E 74 78 74 50 4B 05 06 00 00 00 00 03 00 03 00 A6 00 00 00 86 00 00 00 00 00"
|
31
|
+
bin_format = byte_array_of_zip_file.split.map {|s| s.to_i(16).chr}
|
32
|
+
File.binwrite("embedded_with_folders.zip", bin_format.join)
|
27
33
|
end
|
28
34
|
|
29
35
|
def count_of_files_in(directory_path)
|
data/spec/unit/mundane_spec.rb
CHANGED
@@ -40,6 +40,21 @@ describe "test the algos" do
|
|
40
40
|
|
41
41
|
it 'should make 2 files in the out folder' do
|
42
42
|
drop_dummy_zip_file
|
43
|
+
|
44
|
+
Mundane.zips_to_files
|
45
|
+
count_of_files_in(fake_out_directory).should be 2
|
46
|
+
end
|
47
|
+
|
48
|
+
it "should work on zip archives that have a folder in them" do
|
49
|
+
drop_dummy_zip_file_with_folders
|
50
|
+
|
51
|
+
Mundane.zips_to_files
|
52
|
+
count_of_files_in(fake_out_directory).should be 2
|
53
|
+
end
|
54
|
+
|
55
|
+
it "should ignore files that aren't really archives" do
|
56
|
+
drop_dummy_zip_file
|
57
|
+
drop_dummy_files_in_working_directory
|
43
58
|
|
44
59
|
Mundane.zips_to_files
|
45
60
|
count_of_files_in(fake_out_directory).should be 2
|