Class: Omnizip::Formats::Iso::PathTable
- Inherits:
-
Object
- Object
- Omnizip::Formats::Iso::PathTable
- Defined in:
- lib/omnizip/formats/iso/path_table.rb
Overview
ISO 9660 Path Table Provides efficient directory hierarchy lookup
Defined Under Namespace
Classes: Entry
Instance Attribute Summary collapse
-
#entries ⇒ Object
readonly
Returns the value of attribute entries.
Class Method Summary collapse
-
.parse(data, size) ⇒ PathTable
Parse path table from binary data.
Instance Method Summary collapse
-
#find_by_location(location) ⇒ Entry?
Find entry by location.
-
#find_by_name(name) ⇒ Entry?
Find entry by directory name.
-
#initialize ⇒ PathTable
constructor
Initialize path table.
-
#parse(data, size) ⇒ Object
Parse path table data.
-
#root ⇒ Entry
Get root directory entry.
Constructor Details
#initialize ⇒ PathTable
Initialize path table
49 50 51 |
# File 'lib/omnizip/formats/iso/path_table.rb', line 49 def initialize @entries = [] end |
Instance Attribute Details
#entries ⇒ Object (readonly)
Returns the value of attribute entries.
9 10 11 |
# File 'lib/omnizip/formats/iso/path_table.rb', line 9 def entries @entries end |
Class Method Details
.parse(data, size) ⇒ PathTable
Parse path table from binary data
58 59 60 |
# File 'lib/omnizip/formats/iso/path_table.rb', line 58 def self.parse(data, size) new.tap { |pt| pt.parse(data, size) } end |
Instance Method Details
#find_by_location(location) ⇒ Entry?
Find entry by location
112 113 114 |
# File 'lib/omnizip/formats/iso/path_table.rb', line 112 def find_by_location(location) @entries.find { |e| e.location == location } end |
#find_by_name(name) ⇒ Entry?
Find entry by directory name
104 105 106 |
# File 'lib/omnizip/formats/iso/path_table.rb', line 104 def find_by_name(name) @entries.find { |e| e.name == name } end |
#parse(data, size) ⇒ Object
Parse path table data
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/omnizip/formats/iso/path_table.rb', line 66 def parse(data, size) offset = 0 while offset < size # Byte 0: Length of directory identifier name_length = data.getbyte(offset) break if name_length.zero? # Byte 1: Extended attribute record length data.getbyte(offset + 1) # Bytes 2-5: Location of extent (little-endian) location = data[offset + 2, 4].unpack1("V") # Bytes 6-7: Parent directory number parent = data[offset + 6, 2].unpack1("v") # Bytes 8+: Directory identifier name = data[offset + 8, name_length].strip # Handle root directory (zero-length name) name = "/" if name.empty? # Create entry @entries << Entry.new(name, location, parent) # Move to next entry # Length is 8 + name_length, padded to even boundary record_length = 8 + name_length record_length += 1 if record_length.odd? offset += record_length end end |