mundane 0.0.2 → 0.0.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 34457acc6048618f2422f176abb24819b7425880
4
- data.tar.gz: 5f182b1308a6698ce1176d0aa111565c66f96c66
3
+ metadata.gz: a2f884eb09a064e4a09eeeba3ffaf1521a9faedc
4
+ data.tar.gz: 5526ff7375980336cb4c36516304dec0415bf225
5
5
  SHA512:
6
- metadata.gz: 9da5d04fcb12ee5093dd53b8ab46667345d4594ec8ebfe8da8fec1f96e71ca301d0a168318c290a5e83c1dd201790163c72c52057ed4c47a77348654e3fe0115
7
- data.tar.gz: 830a765dcafc0e0e275cbd7c68a686b681d0ca1cffab08fd00c473373bde98a09a35321fb2200063052ca916493bef1f6af963c40fffc592068038a170108b28
6
+ metadata.gz: 3ab03630bc0aa83ec2b3b163f048ad359f3023b79b8fd5a78b225eef6774b17360274dfb5a11653da5879cbcef18e0d41173de866f60e513036f308b3fef4b59
7
+ data.tar.gz: f215cd036269ceae089f114238e4320e979db4992b8df529572ad716fa90d6d06b8482544f75f53682e2a7409dc8e431f6f2c5eb00fc8a5b6ff85bdc5468a75e
@@ -1,4 +1,3 @@
1
- #require 'pry'
2
1
  require 'zip'
3
2
 
4
3
  require 'mundane/version'
@@ -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
- Zip::File.open(zip) do |archive|
24
- archive.each do |f|
25
- output_path = "out/#{f.name}"
26
- if File.exists? output_path # don't auto-overwrite anything...
27
- puts "#{output_path} ALREADY EXISTED, SKIPPING FILE. DELETE MANUALLY IF NEEDED =/"
28
- incomplete_extractions += 1
29
- next
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
@@ -1,3 +1,3 @@
1
1
  module Mundane
2
- VERSION = '0.0.2'
2
+ VERSION = '0.0.3'
3
3
  end
@@ -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("mine_embedded.zip", bin_format.join)
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)
@@ -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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mundane
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - n-jax