Class: Quake::Pak::Reader
- Inherits:
-
Object
- Object
- Quake::Pak::Reader
- Defined in:
- lib/quake/pak/reader.rb
Constant Summary collapse
- MAGIC =
"PACK"- HEADER_SIZE =
12- DIR_ENTRY_SIZE =
64
Instance Attribute Summary collapse
-
#entries ⇒ Object
readonly
Returns the value of attribute entries.
Instance Method Summary collapse
- #close ⇒ Object
-
#initialize(path) ⇒ Reader
constructor
A new instance of Reader.
- #list ⇒ Object
- #read(name) ⇒ Object
Constructor Details
#initialize(path) ⇒ Reader
Returns a new instance of Reader.
14 15 16 17 18 19 |
# File 'lib/quake/pak/reader.rb', line 14 def initialize(path) @path = path @io = File.open(path, "rb") @entries = {} parse_header end |
Instance Attribute Details
#entries ⇒ Object (readonly)
Returns the value of attribute entries.
12 13 14 |
# File 'lib/quake/pak/reader.rb', line 12 def entries @entries end |
Instance Method Details
#close ⇒ Object
33 34 35 |
# File 'lib/quake/pak/reader.rb', line 33 def close @io.close end |
#list ⇒ Object
21 22 23 |
# File 'lib/quake/pak/reader.rb', line 21 def list @entries.keys end |
#read(name) ⇒ Object
25 26 27 28 29 30 31 |
# File 'lib/quake/pak/reader.rb', line 25 def read(name) entry = @entries[name] || @entries[name.downcase] raise "File not found in PAK: #{name}" unless entry @io.seek(entry.offset) @io.read(entry.size) end |