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
16 17 18 |
# File 'lib/omnizip/formats/rar/decompressor.rb', line 16 def available? gem_available? || command_available? end |
.command_available? ⇒ Boolean
Check if system unrar command is available
46 47 48 |
# File 'lib/omnizip/formats/rar/decompressor.rb', line 46 def command_available? !command_path.nil? end |
.command_path ⇒ String?
Get unrar command path
53 54 55 |
# File 'lib/omnizip/formats/rar/decompressor.rb', line 53 def command_path @command_path ||= find_command end |
.extract(archive_path, output_dir, password: nil) ⇒ Object
Extract RAR archive to directory
63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/omnizip/formats/rar/decompressor.rb', line 63 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
98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/omnizip/formats/rar/decompressor.rb', line 98 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
36 37 38 39 40 41 |
# File 'lib/omnizip/formats/rar/decompressor.rb', line 36 def gem_available? require "unrar" true rescue LoadError false end |
.info ⇒ Hash
Get decompressor information
23 24 25 26 27 28 29 30 31 |
# File 'lib/omnizip/formats/rar/decompressor.rb', line 23 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
80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/omnizip/formats/rar/decompressor.rb', line 80 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 |