Class: Quake::Pak::Reader

Inherits:
Object
  • Object
show all
Defined in:
lib/quake/pak/reader.rb

Constant Summary collapse

MAGIC =
"PACK"
HEADER_SIZE =
12
DIR_ENTRY_SIZE =
64

Instance Attribute Summary collapse

Instance Method Summary collapse

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

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

#closeObject



33
34
35
# File 'lib/quake/pak/reader.rb', line 33

def close
  @io.close
end

#listObject



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