Class: Omnizip::ArchiveHandlers::RarHandler
- Inherits:
-
Object
- Object
- Omnizip::ArchiveHandlers::RarHandler
- Defined in:
- lib/omnizip/archive_handlers/rar_handler.rb
Overview
Read-only adapter for the RAR format. RAR compression is patented software (see link:README[RAR write support]); this handler exposes extraction/listing/reading only, so the convenience API and the Archive facade can operate on existing archives truthfully instead of raising on every operation.
Instance Method Summary collapse
- #create(_path, **_options) ⇒ Object
- #extract_to(path, output_dir, password: nil, **_) ⇒ Object
- #list(path, details: false, **_) ⇒ Object
- #read_entry(path, entry_name, password: nil, **_) ⇒ Object
Instance Method Details
#create(_path, **_options) ⇒ Object
13 14 15 16 17 |
# File 'lib/omnizip/archive_handlers/rar_handler.rb', line 13 def create(_path, **) raise Omnizip::UnsupportedFormatError, "RAR archives cannot be created (patented format); " \ "Omnizip reads RAR archives only" end |
#extract_to(path, output_dir, password: nil, **_) ⇒ Object
19 20 21 22 |
# File 'lib/omnizip/archive_handlers/rar_handler.rb', line 19 def extract_to(path, output_dir, password: nil, **_) Omnizip::Formats::Rar::Decompressor.extract(path, output_dir, password: password) end |
#list(path, details: false, **_) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/omnizip/archive_handlers/rar_handler.rb', line 24 def list(path, details: false, **_) reader = Omnizip::Formats::Rar::Reader.new(path).open entries = reader.list_files if details entries.map do |e| { name: e.name, size: e.size, directory: e.is_dir, mtime: e.mtime } end else entries.map(&:name) end end |
#read_entry(path, entry_name, password: nil, **_) ⇒ Object
37 38 39 40 41 42 43 44 45 |
# File 'lib/omnizip/archive_handlers/rar_handler.rb', line 37 def read_entry(path, entry_name, password: nil, **_) Dir.mktmpdir("omnizip-rar-entry") do |dir| dest = File.join(dir, "entry") Omnizip::Formats::Rar::Decompressor.extract_entry( path, entry_name, dest, password: password ) File.binread(dest) end end |