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
MAX_FILES_IN_PACK =
2048

Instance Attribute Summary collapse

Instance Method Summary collapse

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

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

#closeObject



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

def close
  @io.close
end

#listObject



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