Class: Omnizip::Formats::Rar::Decompressor
- Inherits:
-
Object
- Object
- Omnizip::Formats::Rar::Decompressor
- Defined in:
- lib/omnizip/formats/rar/decompressor.rb
Overview
RAR decompressor wrapper Provides fallback chain: unrar gem → system command → error
Class Method Summary collapse
-
.available? ⇒ Boolean
Check if RAR decompression is available.
-
.command_available? ⇒ Boolean
Check if system unrar command is available.
-
.command_path ⇒ String?
Get unrar command path.
-
.extract(archive_path, output_dir, password: nil) ⇒ Object
Extract RAR archive to directory.
-
.extract_entry(archive_path, entry_name, output_path, password: nil) ⇒ Object
Extract single entry from RAR.
-
.gem_available? ⇒ Boolean
Check if unrar gem is available.
-
.info ⇒ Hash
Get decompressor information.
-
.list(archive_path) ⇒ Array<Hash>
List RAR archive contents.
Class Method Details
.available? ⇒ Boolean
Check if RAR decompression is available
15 16 17 |
# File 'lib/omnizip/formats/rar/decompressor.rb', line 15 def available? gem_available? || command_available? end |
.command_available? ⇒ Boolean
Check if system unrar command is available
45 46 47 |
# File 'lib/omnizip/formats/rar/decompressor.rb', line 45 def command_available? !command_path.nil? end |
.command_path ⇒ String?
Get unrar command path
52 53 54 |
# File 'lib/omnizip/formats/rar/decompressor.rb', line 52 def command_path @command_path ||= find_command end |
.extract(archive_path, output_dir, password: nil) ⇒ Object
Extract RAR archive to directory
62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/omnizip/formats/rar/decompressor.rb', line 62 def extract(archive_path, output_dir, password: nil) raise "RAR extraction not available" unless available? if gem_available? extract_with_gem(archive_path, output_dir, password) elsif command_available? extract_with_command(archive_path, output_dir, password) else raise unsupported_error end end |
.extract_entry(archive_path, entry_name, output_path, password: nil) ⇒ Object
Extract single entry from RAR
97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/omnizip/formats/rar/decompressor.rb', line 97 def extract_entry(archive_path, entry_name, output_path, password: nil) raise "RAR extraction not available" unless available? if gem_available? extract_entry_with_gem(archive_path, entry_name, output_path, password) elsif command_available? extract_entry_with_command(archive_path, entry_name, output_path, password) else raise unsupported_error end end |
.gem_available? ⇒ Boolean
Check if unrar gem is available
35 36 37 38 39 40 |
# File 'lib/omnizip/formats/rar/decompressor.rb', line 35 def gem_available? require "unrar" true rescue LoadError false end |
.info ⇒ Hash
Get decompressor information
22 23 24 25 26 27 28 29 30 |
# File 'lib/omnizip/formats/rar/decompressor.rb', line 22 def info if gem_available? { type: :gem, version: gem_version } elsif command_available? { type: :command, version: command_version } else { type: :none, version: nil } end end |
.list(archive_path) ⇒ Array<Hash>
List RAR archive contents
79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/omnizip/formats/rar/decompressor.rb', line 79 def list(archive_path) raise "RAR extraction not available" unless available? if gem_available? list_with_gem(archive_path) elsif command_available? list_with_command(archive_path) else raise unsupported_error end end |