Class: Omnizip::ArchiveHandlers::IsoHandler

Inherits:
Object
  • Object
show all
Defined in:
lib/omnizip/archive_handlers/iso_handler.rb

Overview

Read-only adapter for the ISO 9660 format (disk images). Extraction and listing are supported; ISO writing exists at the format level but is not exposed through the convenience archive API.

Instance Method Summary collapse

Instance Method Details

#create(_path, **_options) ⇒ Object



12
13
14
15
16
# File 'lib/omnizip/archive_handlers/iso_handler.rb', line 12

def create(_path, **_options)
  raise Omnizip::UnsupportedFormatError,
        "iso images cannot be created through the convenience " \
        "API; use Omnizip::Formats::Iso.create directly"
end

#extract_to(path, output_dir, **_) ⇒ Object



18
19
20
# File 'lib/omnizip/archive_handlers/iso_handler.rb', line 18

def extract_to(path, output_dir, **_)
  Omnizip::Formats::Iso.extract(path, output_dir)
end

#list(path, details: false, **_) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
# File 'lib/omnizip/archive_handlers/iso_handler.rb', line 22

def list(path, details: false, **_)
  entries = Omnizip::Formats::Iso.list(path)
  if details
    entries.map do |e|
      { name: e.full_path, size: e.size, directory: e.directory?,
        mtime: e.recording_date }
    end
  else
    entries.map(&:full_path)
  end
end

#read_entry(path, entry_name, **_) ⇒ Object

Raises:

  • (Errno::EISDIR)


34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/omnizip/archive_handlers/iso_handler.rb', line 34

def read_entry(path, entry_name, **_)
  entry = Omnizip::Formats::Iso.list(path)
    .find { |e| e.full_path == entry_name }
  unless entry
    raise Errno::ENOENT, "Entry not found: #{entry_name}"
  end
  raise Errno::EISDIR, "Entry is a directory: #{entry_name}" if entry.directory?

  Dir.mktmpdir("omnizip-iso-entry") do |dir|
    dest = File.join(dir, "entry")
    Omnizip::Formats::Iso.open(path) do |iso|
      iso.extract_entry(entry_name, dest)
    end
    File.binread(dest)
  end
end