Class: Omnizip::Formats::Iso::PathTable

Inherits:
Object
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializePathTable

Initialize path table



49
50
51
# File 'lib/omnizip/formats/iso/path_table.rb', line 49

def initialize
  @entries = []
end

Instance Attribute Details

#entriesObject (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

Parameters:

  • data (String)

    Binary path table data

  • size (Integer)

    Size of path table in bytes

Returns:



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

Parameters:

  • location (Integer)

    LBA location

Returns:

  • (Entry, nil)

    Found entry or nil



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

Parameters:

  • name (String)

    Directory name

Returns:

  • (Entry, nil)

    Found entry or nil



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

Parameters:

  • data (String)

    Binary data

  • size (Integer)

    Size in bytes



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

#rootEntry

Get root directory entry

Returns:



119
120
121
# File 'lib/omnizip/formats/iso/path_table.rb', line 119

def root
  @entries.first
end