Class: Omnizip::Formats::Iso::Reader

Inherits:
Object
  • Object
show all
Defined in:
lib/omnizip/formats/iso/reader.rb

Overview

ISO 9660 image reader Provides read-only access to ISO filesystem

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file_path) ⇒ Reader

Initialize reader

Parameters:

  • file_path (String)

    Path to ISO file



17
18
19
20
21
22
23
# File 'lib/omnizip/formats/iso/reader.rb', line 17

def initialize(file_path)
  @file_path = file_path
  @primary_volume_descriptor = nil
  @entries = []
  @path_table = nil
  @io = nil
end

Instance Attribute Details

#entriesObject (readonly)

Returns the value of attribute entries.



11
12
13
# File 'lib/omnizip/formats/iso/reader.rb', line 11

def entries
  @entries
end

#file_pathObject (readonly)

Returns the value of attribute file_path.



11
12
13
# File 'lib/omnizip/formats/iso/reader.rb', line 11

def file_path
  @file_path
end

#path_tableObject (readonly)

Returns the value of attribute path_table.



11
12
13
# File 'lib/omnizip/formats/iso/reader.rb', line 11

def path_table
  @path_table
end

#primary_volume_descriptorObject (readonly)

Returns the value of attribute primary_volume_descriptor.



11
12
13
# File 'lib/omnizip/formats/iso/reader.rb', line 11

def primary_volume_descriptor
  @primary_volume_descriptor
end

Instance Method Details

#closeObject

Close ISO file



36
37
38
39
# File 'lib/omnizip/formats/iso/reader.rb', line 36

def close
  @io&.close
  @io = nil
end

#extract_all(output_dir) ⇒ Object

Extract all entries

Parameters:

  • output_dir (String)

    Output directory



87
88
89
90
91
92
93
94
95
96
# File 'lib/omnizip/formats/iso/reader.rb', line 87

def extract_all(output_dir)
  FileUtils.mkdir_p(output_dir)

  @entries.each do |entry|
    next if entry.current_directory? || entry.parent_directory?

    output_path = File.join(output_dir, entry.name)
    extract_entry(entry.name, output_path)
  end
end

#extract_entry(entry_path, output_path) ⇒ Object

Extract entry to file

Parameters:

  • entry_path (String)

    Path in ISO

  • output_path (String)

    Destination path



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/omnizip/formats/iso/reader.rb', line 68

def extract_entry(entry_path, output_path)
  entry = find_entry(entry_path)
  raise "Entry not found: #{entry_path}" unless entry

  if entry.directory?
    FileUtils.mkdir_p(output_path)
  else
    FileUtils.mkdir_p(File.dirname(output_path))
    data = read_file_data(entry)
    File.binwrite(output_path, data)

    # Set modification time if available
    File.utime(entry.mtime, entry.mtime, output_path) if entry.mtime
  end
end

#list_filesArray<DirectoryRecord>

List all entries

Returns:



101
102
103
# File 'lib/omnizip/formats/iso/reader.rb', line 101

def list_files
  @entries.reject { |e| e.current_directory? || e.parent_directory? }
end

#openObject

Open and parse ISO image

Raises:

  • (RuntimeError)

    if file cannot be opened or is invalid



28
29
30
31
32
33
# File 'lib/omnizip/formats/iso/reader.rb', line 28

def open
  @io = File.open(@file_path, "rb")
  parse_volume_descriptors
  parse_directory_structure
  self
end

#system_identifierString

Get system identifier

Returns:

  • (String)

    System identifier



51
52
53
# File 'lib/omnizip/formats/iso/reader.rb', line 51

def system_identifier
  @primary_volume_descriptor&.system_identifier || ""
end

#volume_identifierString

Get volume identifier

Returns:

  • (String)

    Volume name



44
45
46
# File 'lib/omnizip/formats/iso/reader.rb', line 44

def volume_identifier
  @primary_volume_descriptor&.volume_identifier || ""
end

#volume_sizeInteger

Get volume size in bytes

Returns:

  • (Integer)

    Total volume size



58
59
60
61
62
# File 'lib/omnizip/formats/iso/reader.rb', line 58

def volume_size
  return 0 unless @primary_volume_descriptor

  @primary_volume_descriptor.volume_space_size * Iso::SECTOR_SIZE
end