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- MAX_FILES_IN_PACK =
2048
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.
15 16 17 18 19 20 |
# File 'lib/quake/pak/reader.rb', line 15 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.
13 14 15 |
# File 'lib/quake/pak/reader.rb', line 13 def entries @entries end |
Instance Method Details
#close ⇒ Object
34 35 36 |
# File 'lib/quake/pak/reader.rb', line 34 def close @io.close end |
#list ⇒ Object
22 23 24 |
# File 'lib/quake/pak/reader.rb', line 22 def list @entries.keys end |
#read(name) ⇒ Object
26 27 28 29 30 31 32 |
# File 'lib/quake/pak/reader.rb', line 26 def read(name) entry = @entries[name] raise "File not found in PAK: #{name}" unless entry @io.seek(entry.offset) @io.read(entry.size) end |