Class: Exerb::Archive

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

Overview

#

Defined Under Namespace

Classes: Header

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(kcode = 'none') ⇒ Archive



18
19
20
21
22
# File 'lib/exerb/archive.rb', line 18

def initialize(kcode = 'none')
  @name_table   = Exerb::NameTable.new
  @file_table   = Exerb::FileTable.new
  @kcode        = kcode
end

Instance Attribute Details

#file_tableObject (readonly)

Returns the value of attribute file_table



24
25
26
# File 'lib/exerb/archive.rb', line 24

def file_table
  @file_table
end

#kcodeObject

Returns the value of attribute kcode



25
26
27
# File 'lib/exerb/archive.rb', line 25

def kcode
  @kcode
end

#name_tableObject (readonly)

Returns the value of attribute name_table



24
25
26
# File 'lib/exerb/archive.rb', line 24

def name_table
  @name_table
end

Instance Method Details

#add(name, data, flag = 0) ⇒ Object



27
28
29
# File 'lib/exerb/archive.rb', line 27

def add(name, data, flag = 0)
  @file_table.add(@name_table.add(name), data, flag)
end

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



75
76
77
# File 'lib/exerb/archive.rb', line 75

def add_compiled_script(name, data, flag = 0)
  @file_table.add_compiled_script(@name_table.add(name), data, flag)
end

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



79
80
81
# File 'lib/exerb/archive.rb', line 79

def add_compiled_script_from_file(name, path, flag = 0)
  @file_table.add_compiled_script_from_file(@name_table.add(name), path, flag)
end

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



67
68
69
# File 'lib/exerb/archive.rb', line 67

def add_data_binary(name, data, flag = 0)
  @file_table.add_data_binary(@name_table.add(name), data, flag)
end

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



71
72
73
# File 'lib/exerb/archive.rb', line 71

def add_data_binary_from_file(name, path, flag = 0)
  @file_table.add_data_binary_from_file(@name_table.add(name), path, flag)
end

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



51
52
53
# File 'lib/exerb/archive.rb', line 51

def add_dynamic_library(name, data, flag = 0)
  @file_table.add_dynamic_library(@name_table.add(name), data, flag)
end

#add_dynamic_library_from_file(path, flag = 0) ⇒ Object



55
56
57
# File 'lib/exerb/archive.rb', line 55

def add_dynamic_library_from_file(path, flag = 0)
  @file_table.add_dynamic_library_from_file(@name_table.add(File.basename(path)), path, flag)
end

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



43
44
45
# File 'lib/exerb/archive.rb', line 43

def add_extension_library(name, data, flag = 0)
  @file_table.add_extension_library(@name_table.add(name), data, flag)
end

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



47
48
49
# File 'lib/exerb/archive.rb', line 47

def add_extension_library_from_file(name, path, flag = 0)
  @file_table.add_extension_library_from_file(@name_table.add(name), path, flag)
end

#add_from_file(name, path, flag = 0) ⇒ Object



31
32
33
# File 'lib/exerb/archive.rb', line 31

def add_from_file(name, path, flag = 0)
  @file_table.add_from_file(@name_table.add(name), path, flag)
end

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



59
60
61
# File 'lib/exerb/archive.rb', line 59

def add_resource_library(name, data, flag = 0)
  @file_table.add_resource_library(@name_table.add(name), data, flag)
end

#add_resource_library_from_file(path, flag = 0) ⇒ Object



63
64
65
# File 'lib/exerb/archive.rb', line 63

def add_resource_library_from_file(path, flag = 0)
  @file_table.add_resource_library_from_file(@name_table.add(File.basename(path)), path, flag)
end

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



35
36
37
# File 'lib/exerb/archive.rb', line 35

def add_ruby_script(name, data, flag = 0)
  @file_table.add_ruby_script(@name_table.add(name), data, flag)
end

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



39
40
41
# File 'lib/exerb/archive.rb', line 39

def add_ruby_script_from_file(name, path, flag = 0)
  @file_table.add_ruby_script_from_file(@name_table.add(name), path, flag)
end

#packObject



83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/exerb/archive.rb', line 83

def pack
  case @kcode.downcase.delete('-')
  when 'n', 'none' then options = Exerb::Archive::Header::OPTIONS_KCODE_NONE
  when 'e', 'euc'  then options = Exerb::Archive::Header::OPTIONS_KCODE_EUC
  when 's', 'sjis' then options = Exerb::Archive::Header::OPTIONS_KCODE_SJIS
  when 'u', 'utf8' then options = Exerb::Archive::Header::OPTIONS_KCODE_UTF8
  else raise(ExerbError, "unkown kanji code [#{@kcode}]")
  end

  packed_name_table   = @name_table.pack
  packed_file_table   = @file_table.pack

  archive_header = Exerb::Archive::Header.new
  archive_header.signature1             = Exerb::Archive::Header::SIGNATURE1
  archive_header.signature2             = Exerb::Archive::Header::SIGNATURE2
  archive_header.options                = options
  archive_header.offset_of_name_table   = Exerb::Utility.alignment16(archive_header.pack).size
  archive_header.offset_of_file_table   = archive_header.offset_of_name_table + packed_name_table.size

  return Exerb::Utility.alignment16(archive_header.pack) + packed_name_table + packed_file_table
end

#write_to(io) ⇒ Object



105
106
107
# File 'lib/exerb/archive.rb', line 105

def write_to(io)
  io.write(self.pack)
end

#write_to_file(filepath) ⇒ Object



109
110
111
# File 'lib/exerb/archive.rb', line 109

def write_to_file(filepath)
  File.open(filepath, 'wb') { |file| self.write_to(file) }
end