Class: CSstats::Parser::Reader::FileStreamer

Inherits:
Object
  • Object
show all
Defined in:
lib/csstats/parser/reader/file_streamer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(stream) ⇒ FileStreamer

Returns a new instance of FileStreamer.



7
8
9
# File 'lib/csstats/parser/reader/file_streamer.rb', line 7

def initialize(stream)
  @stream = stream
end

Instance Attribute Details

#streamObject (readonly)

Returns the value of attribute stream.



5
6
7
# File 'lib/csstats/parser/reader/file_streamer.rb', line 5

def stream
  @stream
end

Instance Method Details

#read_int_dataObject

Internal: Get the 32bit integer from file.

Returns the Integer.

Raises:



14
15
16
17
18
19
# File 'lib/csstats/parser/reader/file_streamer.rb', line 14

def read_int_data
  data = stream.read(4)
  raise CSstats::Error, 'Cannot read int data.' unless data

  data.unpack('V').first
end

#read_short_dataObject

Internal: Get the 16bit integer from file.

Returns the Integer.

Raises:



24
25
26
27
28
29
# File 'lib/csstats/parser/reader/file_streamer.rb', line 24

def read_short_data
  data = stream.read(2)
  raise CSstats::Error, 'Cannot read short data.' unless data

  data.unpack('v').first
end

#read_string_data(length) ⇒ Object

Internal: Get the String from file.

length - The Integer length of string to read.

Returns the String.

Raises:



36
37
38
39
40
41
# File 'lib/csstats/parser/reader/file_streamer.rb', line 36

def read_string_data(length)
  data = stream.read(length)
  raise CSstats::Error, 'Cannot read string data.' unless data

  data.strip
end