Class: Openra::Replays::File

Inherits:
Object
  • Object
show all
Defined in:
lib/openra/replays/file.rb

Instance Method Summary collapse

Constructor Details

#initialize(filename) ⇒ File

Returns a new instance of File.



6
7
8
# File 'lib/openra/replays/file.rb', line 6

def initialize(filename)
  @filename = filename
end

Instance Method Details

#each_order(&block) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/openra/replays/file.rb', line 10

def each_order(&block)
  return enum_for(:each_order) unless block_given?

  file.rewind

  io = BinData::IO::Read.new(file)
  template = Packet.new(fields: Packet.fields)

  loop do
    begin
      template.new.read(file).orders.each(&block)
    rescue EOFError, IOError
      break
    end
  end
end

#metadataObject



27
28
29
30
31
32
33
34
35
# File 'lib/openra/replays/file.rb', line 27

def 
  # https://github.com/OpenRA/OpenRA/blob/23b3c237b7071fd308c4664b0b6c5d719c0f3c74/OpenRA.Game/FileFormats/ReplayMetadata.cs#L96
  @metadata ||= begin
    io = file.tap(&:rewind)
     = -(.data_length + 4)
    io.seek(, IO::SEEK_END)
    Metadata.read(io)
  end
end