Class: Exerb::FileTable

Inherits:
Object
  • Object
show all
Defined in:
lib/exerb/file_table.rb

Overview

#

Defined Under Namespace

Classes: Entry, Header

Instance Method Summary collapse

Constructor Details

#initializeFileTable


17
18
19
# File 'lib/exerb/file_table.rb', line 17

def initialize
  @entries  = []
end

Instance Method Details

#add(id, data, flag) ⇒ Object


21
22
23
24
# File 'lib/exerb/file_table.rb', line 21

def add(id, data, flag)
  @entries << Exerb::FileTable::Entry.new(id, data, flag)
  return @entries.last
end

#add_compiled_script(id, data, flag = 0) ⇒ Object


70
71
72
# File 'lib/exerb/file_table.rb', line 70

def add_compiled_script(id, data, flag = 0)
  return self.add(id, data, Entry::FLAG_TYPE_COMPILED_SCRIPT | flag)
end

#add_compiled_script_from_file(id, path, flag = 0) ⇒ Object


74
75
76
# File 'lib/exerb/file_table.rb', line 74

def add_compiled_script_from_file(id, path, flag = 0)
  return self.add_from_file(id, path, Entry::FLAG_TYPE_COMPILED_SCRIPT | flag)
end

#add_data_binary(id, data, flag = 0) ⇒ Object


62
63
64
# File 'lib/exerb/file_table.rb', line 62

def add_data_binary(id, data, flag = 0)
  return self.add(id, data, Entry::FLAG_TYPE_DATA_BINARY | flag)
end

#add_data_binary_from_file(id, path, flag = 0) ⇒ Object


66
67
68
# File 'lib/exerb/file_table.rb', line 66

def add_data_binary_from_file(id, path, flag = 0)
  return self.add_from_file(id, path, Entry::FLAG_TYPE_DATA_BINARY | flag)
end

#add_dynamic_library(id, data, flag = 0) ⇒ Object


46
47
48
# File 'lib/exerb/file_table.rb', line 46

def add_dynamic_library(id, data, flag = 0)
  return self.add(id, data, Entry::FLAG_TYPE_DYNAMIC_LIBRARY | flag)
end

#add_dynamic_library_from_file(id, path, flag = 0) ⇒ Object


50
51
52
# File 'lib/exerb/file_table.rb', line 50

def add_dynamic_library_from_file(id, path, flag = 0)
  return self.add_from_file(id, path, Entry::FLAG_TYPE_DYNAMIC_LIBRARY | flag)
end

#add_extension_library(id, data, flag = 0) ⇒ Object


38
39
40
# File 'lib/exerb/file_table.rb', line 38

def add_extension_library(id, data, flag = 0)
  return self.add(id, data, Entry::FLAG_TYPE_EXTENSION_LIBRARY | flag)
end

#add_extension_library_from_file(id, path, flag = 0) ⇒ Object


42
43
44
# File 'lib/exerb/file_table.rb', line 42

def add_extension_library_from_file(id, path, flag = 0)
  return self.add_from_file(id, path, Entry::FLAG_TYPE_EXTENSION_LIBRARY | flag)
end

#add_from_file(id, path, flag) ⇒ Object


26
27
28
# File 'lib/exerb/file_table.rb', line 26

def add_from_file(id, path, flag)
  return File.open(path, 'rb') { |file| self.add(id, file.read, flag) }
end

#add_resource_library(id, data, flag = 0) ⇒ Object


54
55
56
# File 'lib/exerb/file_table.rb', line 54

def add_resource_library(id, data, flag = 0)
  return self.add(id, data, Entry::FLAG_TYPE_RESOURCE_LIBRARY | flag)
end

#add_resource_library_from_file(id, path, flag = 0) ⇒ Object


58
59
60
# File 'lib/exerb/file_table.rb', line 58

def add_resource_library_from_file(id, path, flag = 0)
  return self.add_from_file(id, path, Entry::FLAG_TYPE_RESOURCE_LIBRARY | flag)
end

#add_ruby_script(id, data, flag = 0) ⇒ Object


30
31
32
# File 'lib/exerb/file_table.rb', line 30

def add_ruby_script(id, data, flag = 0)
  return self.add(id, data, Entry::FLAG_TYPE_RUBY_SCRIPT | flag)
end

#add_ruby_script_from_file(id, path, flag = 0) ⇒ Object


34
35
36
# File 'lib/exerb/file_table.rb', line 34

def add_ruby_script_from_file(id, path, flag = 0)
  return self.add_from_file(id, path, Entry::FLAG_TYPE_RUBY_SCRIPT | flag)
end

#packObject


78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/exerb/file_table.rb', line 78

def pack
  headers = ''
  pool    = ''

  @entries.each { |entry|
    headers << entry.pack_header(pool)
    pool    << entry.pack_pool
  }

  packed_headers = Exerb::Utility.alignment16(headers)
  packed_pool    = Exerb::Utility.alignment16(pool)

  table_header = Exerb::FileTable::Header.new
  table_header.signature         = Exerb::FileTable::Header::SIGNATURE
  table_header.number_of_headers = @entries.size
  table_header.offset_of_headers = Exerb::Utility.alignment16(table_header.pack).size
  table_header.offset_of_pool    = table_header.offset_of_headers + packed_headers.size

  return Exerb::Utility.alignment16(table_header.pack) + packed_headers + packed_pool
end