Class: Omnizip::Formats::Iso::Reader
- Inherits:
-
Object
- Object
- Omnizip::Formats::Iso::Reader
- Defined in:
- lib/omnizip/formats/iso/reader.rb
Overview
ISO 9660 image reader Provides read-only access to ISO filesystem
Instance Attribute Summary collapse
-
#entries ⇒ Object
readonly
Returns the value of attribute entries.
-
#file_path ⇒ Object
readonly
Returns the value of attribute file_path.
-
#path_table ⇒ Object
readonly
Returns the value of attribute path_table.
-
#primary_volume_descriptor ⇒ Object
readonly
Returns the value of attribute primary_volume_descriptor.
Instance Method Summary collapse
-
#close ⇒ Object
Close ISO file.
-
#extract_all(output_dir) ⇒ Object
Extract all entries.
-
#extract_entry(entry_path, output_path) ⇒ Object
Extract entry to file.
-
#initialize(file_path) ⇒ Reader
constructor
Initialize reader.
-
#list_files ⇒ Array<DirectoryRecord>
List all entries.
-
#open ⇒ Object
Open and parse ISO image.
-
#system_identifier ⇒ String
Get system identifier.
-
#volume_identifier ⇒ String
Get volume identifier.
-
#volume_size ⇒ Integer
Get volume size in bytes.
Constructor Details
#initialize(file_path) ⇒ Reader
Initialize reader
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
#entries ⇒ Object (readonly)
Returns the value of attribute entries.
11 12 13 |
# File 'lib/omnizip/formats/iso/reader.rb', line 11 def entries @entries end |
#file_path ⇒ Object (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_table ⇒ Object (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_descriptor ⇒ Object (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
#close ⇒ Object
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
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
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_files ⇒ Array<DirectoryRecord>
List all entries
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 |
#open ⇒ Object
Open and parse ISO image
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_identifier ⇒ String
Get system identifier
51 52 53 |
# File 'lib/omnizip/formats/iso/reader.rb', line 51 def system_identifier @primary_volume_descriptor&.system_identifier || "" end |
#volume_identifier ⇒ String
Get volume identifier
44 45 46 |
# File 'lib/omnizip/formats/iso/reader.rb', line 44 def volume_identifier @primary_volume_descriptor&.volume_identifier || "" end |
#volume_size ⇒ Integer
Get volume size in bytes
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 |