class Openra::Replays::File
Attributes
filename[R]
Public Class Methods
new(filename)
click to toggle source
# File lib/openra/replays/file.rb, line 6 def initialize(filename) @filename = filename end
Public Instance Methods
each_order(&block)
click to toggle source
# 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
generate_hash()
click to toggle source
# File lib/openra/replays/file.rb, line 27 def generate_hash Digest::SHA256.hexdigest(file.read) end
metadata()
click to toggle source
# File lib/openra/replays/file.rb, line 31 def metadata # https://github.com/OpenRA/OpenRA/blob/23b3c237b7071fd308c4664b0b6c5d719c0f3c74/OpenRA.Game/FileFormats/ReplayMetadata.cs#L96 @metadata ||= begin io = file.tap(&:rewind) metadata_offset = -(metadata_marker.data_length + 4) io.seek(metadata_offset, IO::SEEK_END) Metadata.read(io) end end
Private Instance Methods
file()
click to toggle source
# File lib/openra/replays/file.rb, line 45 def file @file ||= ::File.open(filename, 'rb') end
metadata_marker()
click to toggle source
# File lib/openra/replays/file.rb, line 49 def metadata_marker @metadata_marker ||= MetadataMarker.read(file) end