dearchiver 0.0.1

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.
@@ -0,0 +1,15 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ coverage
6
+ spec/reports
7
+
8
+ # YARD artifacts
9
+ .yardoc
10
+ _yardoc
11
+ doc/
12
+
13
+ .idea
14
+ .idea/**/*
15
+ atlassian-ide-plugin.xml
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format=nested
@@ -0,0 +1,2 @@
1
+ --markup markdown
2
+ {lib}/**/*.rb
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in dearchiver.gemspec
4
+ gemspec
@@ -0,0 +1,34 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ dearchiver (0.0.1)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ diff-lcs (1.1.3)
10
+ multi_json (1.3.6)
11
+ rake (0.9.2.2)
12
+ rspec (2.11.0)
13
+ rspec-core (~> 2.11.0)
14
+ rspec-expectations (~> 2.11.0)
15
+ rspec-mocks (~> 2.11.0)
16
+ rspec-core (2.11.1)
17
+ rspec-expectations (2.11.3)
18
+ diff-lcs (~> 1.1.3)
19
+ rspec-mocks (2.11.3)
20
+ simplecov (0.6.4)
21
+ multi_json (~> 1.0)
22
+ simplecov-html (~> 0.5.3)
23
+ simplecov-html (0.5.3)
24
+ yard (0.8.3)
25
+
26
+ PLATFORMS
27
+ ruby
28
+
29
+ DEPENDENCIES
30
+ dearchiver!
31
+ rake
32
+ rspec (~> 2.6)
33
+ simplecov (~> 0.5)
34
+ yard (~> 0.8.3)
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 eljuanchosf
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,58 @@
1
+ # Dearchiver
2
+
3
+ A simple Ruby Gem to decompress and check the CRC of compressed files.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'dearchiver'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install dearchiver
18
+
19
+ ## Usage
20
+
21
+ Dearchiver will use the command line of your operating system to perform the desired operations in the
22
+ compressed files. This means that you **need** to have utilities installed (say *unzip*, *unrar*, *7zip* and *tar*).
23
+
24
+ Usage is very simple.
25
+
26
+ Just for now the gem will work only of the following type of files:
27
+
28
+ .zip
29
+ .rar
30
+ .tar.gz
31
+ .7z
32
+
33
+ **TESTED ON Ubuntu 10.04**: No idea how it is going to behave in other OS.
34
+
35
+ ### Checking CRC
36
+
37
+ da = Dearchiver.new(:filename => "foo.zip")
38
+ da.crc_ok?
39
+
40
+ If the filename doesn't have any extension, you can use:
41
+
42
+ da = Dearchiver.new(:filename => "foo", :archive_type => ".zip")
43
+ da.crc_ok?
44
+
45
+ ### Extracting files
46
+
47
+ da = Dearchiver.new(:filename => "foo.zip")
48
+ da.extract_to("/tmp")
49
+ puts da.list_of_files
50
+
51
+ ## Contributing
52
+
53
+ 1. Fork it
54
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
55
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
56
+ 4. Push to the branch (`git push origin my-new-feature`)
57
+ 5. Create new Pull Request
58
+
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env rake
2
+ require 'bundler'
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
5
+
6
+ RSpec::Core::RakeTask.new(:test) do |t|
7
+ t.pattern = 'spec/*_spec.rb'
8
+ t.verbose = false
9
+ end
10
+
11
+ task :default => :test
@@ -0,0 +1,22 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/dearchiver/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["eljuanchosf"]
6
+ gem.email = ["juanpgenovese@gmail.com"]
7
+ gem.description = %q{Ruby Gem to decompress and check the CRC of compressed files.}
8
+ gem.summary = %q{A simple Ruby Gem to decompress and check the CRC of compressed files.}
9
+ gem.homepage = "http://www.github.com/eljuanchosf/dearchiver"
10
+
11
+ gem.add_development_dependency 'rake'
12
+ gem.add_development_dependency 'rspec', '~> 2.6'
13
+ gem.add_development_dependency 'simplecov', '~> 0.5'
14
+ gem.add_development_dependency 'yard', '~> 0.8.3'
15
+
16
+ gem.files = `git ls-files`.split($\)
17
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
18
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
19
+ gem.name = "dearchiver"
20
+ gem.require_paths = ["lib"]
21
+ gem.version = Dearchiver::VERSION
22
+ end
@@ -0,0 +1,15 @@
1
+ require "dearchiver/processor"
2
+ require "dearchiver/version"
3
+
4
+ module Dearchiver
5
+
6
+ class << self
7
+ # Shorthand to Dearchiver::Processor.new
8
+ #
9
+ # @return [Dearchiver::Processor]
10
+ #
11
+ def new(options={})
12
+ Dearchiver::Processor.new(options)
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,121 @@
1
+ module Dearchiver
2
+ # @author Juan Pablo Genovese
3
+ #
4
+ class Processor
5
+
6
+ # Returns a String with the filename
7
+ attr_reader :filename
8
+ # Returns a String the archive type
9
+ attr_reader :archive_type
10
+ # Returns an Array of strings with the list of extracted files
11
+ attr_reader :list_of_files
12
+ # Returns a String with the command executed
13
+ attr_reader :executed_command
14
+ # Returns a String with the result of the executed command
15
+ attr_reader :execution_output
16
+
17
+ # Initialize a new Dearchiver::Processor object
18
+ #
19
+ # Possible values for **options**
20
+ #
21
+ # **:filename** - The complete filename (with included path) to work with.
22
+ #
23
+ # **:archive_type** - Optional. See archive_options for recognized file types.
24
+ #
25
+ # @param [Hash] options set of configuration options
26
+ #
27
+ # @return [Dearchiver::Processor]
28
+ #
29
+ def initialize(options = {})
30
+ @filename = options[:filename]
31
+ raise ArgumentError, "Processor: :filename required!" if @filename.nil? or @filename.empty?
32
+
33
+ if options[:archive_type].nil? or options[:archive_type].empty?
34
+ @archive_type = File.extname(@filename) if valid_file_type?
35
+ end
36
+ @archive_type ||= options[:archive_type]
37
+ raise ArgumentError, "Processor: :archive_type required. :filename does not contain a recognizable extension!" if @archive_type.nil? or @archive_type.empty?
38
+ end
39
+
40
+ # Checks the CRC of the file
41
+ #
42
+ # Returns true if the CRC is Ok, false otherwise
43
+ #
44
+ # @return [Boolean]
45
+ #
46
+ def crc_ok?
47
+ result = execute_command(archive_options[@archive_type][:crc_check].gsub("<filename>", filename))
48
+ result.include?(archive_options[@archive_type][:crc_ok]) ? true : false
49
+ end
50
+
51
+
52
+ # Extracts the content of the compressed file to the specified directory.
53
+ # Warning: it will overwrite the existing files without asking.
54
+ #
55
+ # @param [String] destination the directory with full path to extracts the files to.
56
+ #
57
+ # @return [Array] an array of strings with the extracted file list.
58
+ #
59
+ def extract_to(destination)
60
+ raise ArgumentError, "Processor: destination is required!" if destination.nil? or destination.empty?
61
+ raise RuntimeError, "destination directory is not valid" unless Dir.exists?(destination)
62
+
63
+ @list_of_files = []
64
+ result = execute_command(archive_options[@archive_type][:decompress].gsub("<filename>", filename).gsub("<extractdir>", destination))
65
+ result.scan(archive_options[@archive_type][:file_list_regex]).each do |slice|
66
+ # The gsub("\b","") is a hack to make the list file for unrar work.
67
+ @list_of_files << slice.first.gsub("\b","").strip
68
+ end
69
+ @list_of_files
70
+ end
71
+
72
+ private
73
+
74
+ def execute_command(command)
75
+ @executed_command = command
76
+ result = %x[#{command}]
77
+ @execution_output = result
78
+ result
79
+ end
80
+
81
+ def archive_options
82
+ {
83
+ ".zip" => {
84
+ :crc_check => "unzip -t <filename>",
85
+ :crc_ok => "No errors detected in compressed data",
86
+ :decompress => "unzip -o <filename> -d <extractdir>",
87
+ :file_list_regex => /extracting: (.+)/,
88
+ :compress => "zip <extractdir>/<filename> <extractdir>/<filename>"
89
+ },
90
+ ".rar" => {
91
+ :crc_check => "unrar t <filename>",
92
+ :crc_ok => "All OK",
93
+ :decompress => "unrar x -y <filename> <extractdir>",
94
+ :file_list_regex => /Extracting ([\w\dA-Za-z\/\-\.]*)/,
95
+ :compress => ""
96
+ },
97
+ ".7z" => {
98
+ :crc_check => "7z t <filename>",
99
+ :crc_ok => "Everything is Ok",
100
+ :decompress => "7z x -y <filename> -o<extractdir>",
101
+ :file_list_regex => /Extracting + ([\d\w\.]+)/,
102
+ :compress => "7z a -mx9 <destination_filename> <filename>"
103
+
104
+ },
105
+ ".gz" => {
106
+ :crc_check => "gunzip -t <filename>",
107
+ :crc_ok => "",
108
+ :decompress => "tar xvzf <filename> --overwrite -C <extractdir>",
109
+ #/[\-rwx]+ \w+\/\w+ +\d+ [\d\-\/]+ [\d:]+ (.*)/ -> For CRC only??
110
+ :file_list_regex => /(.*)/,
111
+ :compress => ""
112
+ }
113
+ }
114
+ end
115
+
116
+ def valid_file_type?
117
+ archive_options.has_key?(File.extname(@filename))
118
+ end
119
+
120
+ end
121
+ end
@@ -0,0 +1,3 @@
1
+ module Dearchiver
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,21 @@
1
+ require "spec_helper"
2
+
3
+ describe "Dearchiver::Processor" do
4
+ it "should create an instance of Dearchiver via .new" do
5
+ Dearchiver.respond_to?(:new).should == true
6
+ Dearchiver.new(:filename => 'foo.zip').should be_a Dearchiver::Processor
7
+ end
8
+
9
+ it "should create an instance if all the argmuments are correct" do
10
+ Dearchiver.new(:filename => 'foo.bar', :archive_type => ".zip").should be_a Dearchiver::Processor
11
+ end
12
+
13
+ it "should raise an error if no filename is passed as an argument" do
14
+ expect { Dearchiver.new }.to raise_error(ArgumentError)
15
+ end
16
+
17
+ it "should raise an error if a file type is not recognized and type not passed" do
18
+ expect { Dearchiver.new(:filename => "foo.bar") }.to raise_error(ArgumentError)
19
+ end
20
+
21
+ end
Binary file
Binary file
Binary file
Binary file
Binary file
@@ -0,0 +1,96 @@
1
+ require "spec_helper"
2
+
3
+ describe "Dearchiver::Processor" do
4
+
5
+ before :all do
6
+ fixtures_dir = File.join(File.dirname(__FILE__),'fixtures')
7
+
8
+ @tmp_dir = File.join(File.dirname(__FILE__),'tmp')
9
+
10
+ @extracted_test_file = File.join(@tmp_dir, "test.txt")
11
+
12
+ @zip_file = File.join(fixtures_dir,'test.zip')
13
+ @rar_file = File.join(fixtures_dir,'test.rar')
14
+ @sevenz_file = File.join(fixtures_dir,'test.7z')
15
+ @tar_file = File.join(fixtures_dir,'test.tar.gz')
16
+ @zip_file_without_extension = File.join(fixtures_dir,'testzip')
17
+
18
+ # Create the tmp dir if doesn't exist
19
+ Dir.mkdir(@tmp_dir) unless Dir.exists?(@tmp_dir)
20
+ end
21
+
22
+ after :all do
23
+ # Delete the tmp dir if exists
24
+ Dir.rmdir(@tmp_dir) if Dir.exists?(@tmp_dir)
25
+ end
26
+
27
+ after :each do
28
+ # Clear the tmp directory
29
+ Dir.foreach(@tmp_dir) do |f|
30
+ unless File.directory?(File.join(@tmp_dir, f))
31
+ File.delete(File.join(@tmp_dir, f))
32
+ end
33
+ end
34
+ end
35
+
36
+ it "should verify a zip file crc" do
37
+ da = Dearchiver.new(:filename => @zip_file)
38
+ da.crc_ok?.should be true
39
+ end
40
+
41
+ it "should verify a rar file crc" do
42
+ da = Dearchiver.new(:filename => @rar_file)
43
+ da.crc_ok?.should be true
44
+ end
45
+
46
+ it "should verify a 7z file crc" do
47
+ da = Dearchiver.new(:filename => @sevenz_file)
48
+ da.crc_ok?.should be true
49
+ end
50
+
51
+ it "should verify a gz file crc" do
52
+ da = Dearchiver.new(:filename => @tar_file)
53
+ da.crc_ok?.should be true
54
+ end
55
+
56
+ it "should verify for crc without file extension" do
57
+ da = Dearchiver.new(:filename => @zip_file_without_extension, :archive_type => '.zip')
58
+ da.crc_ok?.should be true
59
+ end
60
+
61
+ it "should extract a zip file and return a list of files" do
62
+ da = Dearchiver.new(:filename => @zip_file)
63
+ da.extract_to(@tmp_dir).should be_an Array
64
+ da.list_of_files[0].should == @extracted_test_file
65
+ end
66
+
67
+ it "should extract a rar file and return a list of files" do
68
+ da = Dearchiver.new(:filename => @rar_file)
69
+ da.extract_to(@tmp_dir).should be_an Array
70
+ da.list_of_files[0].should == @extracted_test_file
71
+ end
72
+
73
+ it "should extract a 7z file and return a list of files" do
74
+ da = Dearchiver.new(:filename => @sevenz_file)
75
+ da.extract_to(@tmp_dir).should be_an Array
76
+ da.list_of_files[0].should == "test.txt"
77
+ end
78
+
79
+ it "should extract a gz file and return a list of files" do
80
+ da = Dearchiver.new(:filename => @tar_file)
81
+ da.extract_to(@tmp_dir).should be_an Array
82
+ da.list_of_files[0].should == "test.txt"
83
+ end
84
+
85
+ it "should maintain a execution command for inspection" do
86
+ da = Dearchiver.new(:filename => @zip_file)
87
+ da.extract_to(@tmp_dir)
88
+ da.execution_output.should be_a String
89
+ end
90
+
91
+ it "should raise an error if it is a non existing directory" do
92
+ da = Dearchiver.new(:filename => @zip_file)
93
+ expect { da.extract_to("/false/directory") }.to raise_error RuntimeError
94
+ end
95
+
96
+ end
@@ -0,0 +1,8 @@
1
+ $:.unshift File.expand_path("../..", __FILE__)
2
+
3
+ require 'dearchiver'
4
+ require 'simplecov'
5
+
6
+ SimpleCov.start do
7
+ add_group 'DeArchiver', 'lib/dearchiver'
8
+ end
metadata ADDED
@@ -0,0 +1,118 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dearchiver
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - eljuanchosf
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-10-26 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rake
16
+ requirement: &14673760 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: *14673760
25
+ - !ruby/object:Gem::Dependency
26
+ name: rspec
27
+ requirement: &14673040 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ~>
31
+ - !ruby/object:Gem::Version
32
+ version: '2.6'
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *14673040
36
+ - !ruby/object:Gem::Dependency
37
+ name: simplecov
38
+ requirement: &14672180 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ~>
42
+ - !ruby/object:Gem::Version
43
+ version: '0.5'
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *14672180
47
+ - !ruby/object:Gem::Dependency
48
+ name: yard
49
+ requirement: &14671440 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: 0.8.3
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: *14671440
58
+ description: Ruby Gem to decompress and check the CRC of compressed files.
59
+ email:
60
+ - juanpgenovese@gmail.com
61
+ executables: []
62
+ extensions: []
63
+ extra_rdoc_files: []
64
+ files:
65
+ - .gitignore
66
+ - .rspec
67
+ - .yardopts
68
+ - Gemfile
69
+ - Gemfile.lock
70
+ - LICENSE
71
+ - README.md
72
+ - Rakefile
73
+ - dearchiver.gemspec
74
+ - lib/dearchiver.rb
75
+ - lib/dearchiver/processor.rb
76
+ - lib/dearchiver/version.rb
77
+ - spec/dearchiver_spec.rb
78
+ - spec/fixtures/test.7z
79
+ - spec/fixtures/test.rar
80
+ - spec/fixtures/test.tar.gz
81
+ - spec/fixtures/test.zip
82
+ - spec/fixtures/testzip
83
+ - spec/processor_spec.rb
84
+ - spec/spec_helper.rb
85
+ homepage: http://www.github.com/eljuanchosf/dearchiver
86
+ licenses: []
87
+ post_install_message:
88
+ rdoc_options: []
89
+ require_paths:
90
+ - lib
91
+ required_ruby_version: !ruby/object:Gem::Requirement
92
+ none: false
93
+ requirements:
94
+ - - ! '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ required_rubygems_version: !ruby/object:Gem::Requirement
98
+ none: false
99
+ requirements:
100
+ - - ! '>='
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ requirements: []
104
+ rubyforge_project:
105
+ rubygems_version: 1.8.10
106
+ signing_key:
107
+ specification_version: 3
108
+ summary: A simple Ruby Gem to decompress and check the CRC of compressed files.
109
+ test_files:
110
+ - spec/dearchiver_spec.rb
111
+ - spec/fixtures/test.7z
112
+ - spec/fixtures/test.rar
113
+ - spec/fixtures/test.tar.gz
114
+ - spec/fixtures/test.zip
115
+ - spec/fixtures/testzip
116
+ - spec/processor_spec.rb
117
+ - spec/spec_helper.rb
118
+ has_rdoc: