Class: Helpers::SubStreamView

Inherits:
BaseStreamView show all
Defined in:
lib/file_data/helpers/stream_view.rb

Overview

View of a stream that has a specified size in bytes

Instance Attribute Summary collapse

Attributes inherited from BaseStreamView

#start_pos, #stream

Instance Method Summary collapse

Methods included from BinaryExtensions

#read_ascii, #read_value

Constructor Details

#initialize(stream, start_pos, size) ⇒ SubStreamView

Returns a new instance of SubStreamView.



24
25
26
27
28
# File 'lib/file_data/helpers/stream_view.rb', line 24

def initialize(stream, start_pos, size)
  super(stream, start_pos)
  @end_pos = @start_pos + size - 1
  @size = size
end

Instance Attribute Details

#end_posObject (readonly)

Returns the value of attribute end_pos.



22
23
24
# File 'lib/file_data/helpers/stream_view.rb', line 22

def end_pos
  @end_pos
end

#sizeObject (readonly)

Returns the value of attribute size.



22
23
24
# File 'lib/file_data/helpers/stream_view.rb', line 22

def size
  @size
end

Instance Method Details

#eof?Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/file_data/helpers/stream_view.rb', line 34

def eof?
  pos > @end_pos || @stream.eof?
end

#remaining_bytesObject



30
31
32
# File 'lib/file_data/helpers/stream_view.rb', line 30

def remaining_bytes
  @end_pos - pos + 1
end