rar 0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.yardopts +5 -0
- data/LICENSE +13 -0
- data/README.md +54 -0
- data/library/rar.rb +46 -0
- data/library/rar/archive.rb +78 -0
- data/library/rar/command_line_options.rb +26 -0
- data/library/rar/version.rb +13 -0
- metadata +101 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 142dbffb47cce75ea7de10b407a2a103486330eb
|
4
|
+
data.tar.gz: 5c66d66bcae8e0bb1a2a3bf6c0ee98953cf21899
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: a096bd80b400449335222afcd3b4624a26201512de8e0c100885358938100c3cf64f3135e30fbc34864c6b6c8b26c2e0563b4df8c7f18707b4d2b6a4be1587c1
|
7
|
+
data.tar.gz: 08dbe55dfc63e46c61d02953833e47b454ae74486fe5a742ab7b3d1b21d0944a3df299ccfa53fe636d5fd08770de411424d60c912bbfdc8e2eff75fb149817db
|
data/.yardopts
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
Copyright (c) 2014, Mikkel Kroman <mk@uplink.io>
|
2
|
+
|
3
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
4
|
+
purpose with or without fee is hereby granted, provided that the above
|
5
|
+
copyright notice and this permission notice appear in all copies.
|
6
|
+
|
7
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
8
|
+
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
9
|
+
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
10
|
+
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
11
|
+
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
12
|
+
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
13
|
+
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
# RAR
|
2
|
+
|
3
|
+
RAR is a Ruby wrapper for the command-line application `rar`, also known as
|
4
|
+
WinRAR for Windows. A free evaluation copy can be obtained from [RarLab](http://rarlab.com).
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
`gem install rar`
|
9
|
+
|
10
|
+
And you're all set. Extra dependencies will automatically be installed.
|
11
|
+
|
12
|
+
## Usage
|
13
|
+
|
14
|
+
### Creating an archive
|
15
|
+
|
16
|
+
Creating an archive and adding arbitrary files to it is simple!
|
17
|
+
|
18
|
+
require 'rar'
|
19
|
+
|
20
|
+
archive = RAR::Archive.new 'archive.rar'
|
21
|
+
|
22
|
+
archive.add_file 'some-file.txt'
|
23
|
+
archive.add_file 'some-other-file.jpg'
|
24
|
+
|
25
|
+
archive.create!
|
26
|
+
|
27
|
+
### Adding command-line options
|
28
|
+
|
29
|
+
RAR provides a mapping of verbosely named options for ease of use.
|
30
|
+
|
31
|
+
archive = RAR::Archive.new 'archive.rar', volume_size: 15_000_000
|
32
|
+
|
33
|
+
archive.add_file 'some-file.txt'
|
34
|
+
archive.add_file 'some-large-file.bin'
|
35
|
+
|
36
|
+
archive.create!
|
37
|
+
|
38
|
+
This example splits the archive into multiple volumes with a size of 15MB.
|
39
|
+
|
40
|
+
To see more options, take a look at the documentation.
|
41
|
+
|
42
|
+
## Contributing
|
43
|
+
|
44
|
+
1. Fork it!
|
45
|
+
2. Create your feature branch: `git checkout -b my-new-feature`
|
46
|
+
3. Commit your changes: `git commit -am 'Add some feature'`
|
47
|
+
4. Push to the branch: `git push origin my-new-feature`
|
48
|
+
5. Submit a pull request
|
49
|
+
|
50
|
+
## History
|
51
|
+
|
52
|
+
__v0.1__
|
53
|
+
|
54
|
+
+ Initial release.
|
data/library/rar.rb
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'open3'
|
4
|
+
require 'shellwords'
|
5
|
+
|
6
|
+
require 'rar/version'
|
7
|
+
require 'rar/archive'
|
8
|
+
require 'rar/command_line_options'
|
9
|
+
|
10
|
+
# RAR is a Ruby wrapper for the command-line application rar, also known as
|
11
|
+
# WinRAR for Windows. A free evaluation copy can be obtained from RarLab.
|
12
|
+
#
|
13
|
+
#
|
14
|
+
module RAR
|
15
|
+
# A list of messages of what the process exit code might indicate.
|
16
|
+
ExitCodeMessages = {
|
17
|
+
0 => 'Successful operation.',
|
18
|
+
1 => 'Non fatal error(s) occurred.',
|
19
|
+
2 => 'A fatal error occurred.',
|
20
|
+
3 => 'Invalid checksum. Data is damaged.',
|
21
|
+
4 => 'Attempt to modify an archive locked by \'k\' command.',
|
22
|
+
5 => 'Write error.',
|
23
|
+
6 => 'File open error.',
|
24
|
+
7 => 'Wrong command line option.',
|
25
|
+
8 => 'Not enough memory.',
|
26
|
+
9 => 'File creation error.',
|
27
|
+
10 => 'No files matching the specified mask and options were found.',
|
28
|
+
11 => 'Wrong password.',
|
29
|
+
255 => 'User stopped the process.'
|
30
|
+
}
|
31
|
+
|
32
|
+
# The standard error for unexpected exit codes.
|
33
|
+
CommandLineError = Class.new StandardError
|
34
|
+
|
35
|
+
# Set the path to the executable `rar` file.
|
36
|
+
#
|
37
|
+
# @return [String] the new path to the executable.
|
38
|
+
def self.executable= executable
|
39
|
+
@executable = executable
|
40
|
+
end
|
41
|
+
|
42
|
+
# @return [String] the path to the executable `rar` file.
|
43
|
+
def self.executable
|
44
|
+
@executable || 'rar'
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,78 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module RAR
|
4
|
+
# The Archive class.
|
5
|
+
#
|
6
|
+
# It is the main entry-point to creating a new archive.
|
7
|
+
class Archive
|
8
|
+
# @return [Array] the list of files.
|
9
|
+
attr_accessor :files
|
10
|
+
|
11
|
+
# @return [Hash] the list of options.
|
12
|
+
attr_accessor :options
|
13
|
+
|
14
|
+
# Create a new archive.
|
15
|
+
#
|
16
|
+
# @param [String] filename The archive's file name.
|
17
|
+
# @param [CommandLineOptions, optional] options The options to pass to the
|
18
|
+
# command line.
|
19
|
+
#
|
20
|
+
# @option options [String] :extra A string of command line options that will
|
21
|
+
# be passed directly to the command line.
|
22
|
+
# @option options [Boolean] :force Assume Yes on all queries.
|
23
|
+
# @option options [Boolean] :old_format Use the old style volume naming
|
24
|
+
# scheme.
|
25
|
+
# @option options [Fixnum, String] :volume_size The volume size in case of
|
26
|
+
# multiple volumes.
|
27
|
+
# @option options [Fixnum] :compression Set compression level.
|
28
|
+
# (0-store...3-default...5-maximal)
|
29
|
+
# @option options [Boolean] :exclude_path Exclude paths from names.
|
30
|
+
def initialize filename, options = {}
|
31
|
+
@files = []
|
32
|
+
@options = CommandLineOptions.new.merge options
|
33
|
+
@filename = filename
|
34
|
+
end
|
35
|
+
|
36
|
+
# Add a file to the list of files.
|
37
|
+
#
|
38
|
+
# @return [Array] the list of files.
|
39
|
+
# @raise ERRNO::ENOENT if the file doesn't exist.
|
40
|
+
def add_file path
|
41
|
+
if File.exist? path
|
42
|
+
@files << path
|
43
|
+
else
|
44
|
+
raise Errno::ENOENT, "File '#{path}' doesn't exist"
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
# Create the final archive.
|
49
|
+
#
|
50
|
+
# @raise CommandLineError if the exit code indicates an error.
|
51
|
+
# @return true if the command executes without a hitch.
|
52
|
+
def create!
|
53
|
+
`#{command_line}`
|
54
|
+
|
55
|
+
if $? > 1
|
56
|
+
if message = ExitCodeMessage[$?]
|
57
|
+
raise CommandLineError, message
|
58
|
+
else
|
59
|
+
raise CommandLineError, "Unknown exit code: #{$?}"
|
60
|
+
end
|
61
|
+
else
|
62
|
+
true
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
private
|
67
|
+
|
68
|
+
# @return [String] the concatenated list of command-line switches.
|
69
|
+
def command_line_options
|
70
|
+
Shellwords.join @options.to_a
|
71
|
+
end
|
72
|
+
|
73
|
+
# @return [String] the concatenated command-line with all the switches.
|
74
|
+
def command_line
|
75
|
+
%{#{RAR.executable} a #{command_line_options} #{Shellwords.escape @filename} #{Shellwords.join @files}}
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module RAR
|
4
|
+
# CommandLineOptions is a convenience class to making adding new command-line
|
5
|
+
# switches trivial.
|
6
|
+
class CommandLineOptions < Hash
|
7
|
+
# The mappings that convert an option to an actual command line switch.
|
8
|
+
OptionsMap = {
|
9
|
+
extra: ->(extra) { extra },
|
10
|
+
force: ->(force) { '-y' if force },
|
11
|
+
old_format: ->(old_format) { '-vn' if old_format },
|
12
|
+
volume_size: ->(volume_size) { "-v#{volume_size}" },
|
13
|
+
compression: ->(compression = 0) { "-m#{compression}" },
|
14
|
+
exclude_path: ->(exclude_path) { 'ep' },
|
15
|
+
}
|
16
|
+
|
17
|
+
# @return [Array] the list of command line options.
|
18
|
+
def to_a
|
19
|
+
map do |key, value|
|
20
|
+
if block = OptionsMap[key]
|
21
|
+
block.call value
|
22
|
+
end
|
23
|
+
end.compact
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
metadata
ADDED
@@ -0,0 +1,101 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rar
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: '0.1'
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Mikkel Kroman
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-07-04 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rspec
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '3.0'
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 3.0.0
|
23
|
+
type: :development
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - "~>"
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '3.0'
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 3.0.0
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: guard
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - "~>"
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '2.6'
|
40
|
+
type: :development
|
41
|
+
prerelease: false
|
42
|
+
version_requirements: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - "~>"
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '2.6'
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: guard-rspec
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - "~>"
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '4.2'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - "~>"
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '4.2'
|
61
|
+
description: |2
|
62
|
+
RAR is a Ruby wrapper for the command-line application rar, also known as WinRAR for Windows.
|
63
|
+
email: mk@uplink.io
|
64
|
+
executables: []
|
65
|
+
extensions: []
|
66
|
+
extra_rdoc_files: []
|
67
|
+
files:
|
68
|
+
- ".yardopts"
|
69
|
+
- LICENSE
|
70
|
+
- README.md
|
71
|
+
- library/rar.rb
|
72
|
+
- library/rar/archive.rb
|
73
|
+
- library/rar/command_line_options.rb
|
74
|
+
- library/rar/version.rb
|
75
|
+
homepage: https://github.com/mkroman/rar
|
76
|
+
licenses:
|
77
|
+
- MIT
|
78
|
+
metadata: {}
|
79
|
+
post_install_message:
|
80
|
+
rdoc_options: []
|
81
|
+
require_paths:
|
82
|
+
- library
|
83
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
84
|
+
requirements:
|
85
|
+
- - ">="
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: '0'
|
88
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
89
|
+
requirements:
|
90
|
+
- - ">="
|
91
|
+
- !ruby/object:Gem::Version
|
92
|
+
version: '0'
|
93
|
+
requirements: []
|
94
|
+
rubyforge_project:
|
95
|
+
rubygems_version: 2.2.2
|
96
|
+
signing_key:
|
97
|
+
specification_version: 4
|
98
|
+
summary: RAR is a Ruby wrapper for the command-line application rar, also known as
|
99
|
+
WinRAR for Windows.
|
100
|
+
test_files: []
|
101
|
+
has_rdoc:
|