Class: WahWah::Ogg::Page

Inherits:
Object
  • Object
show all
Defined in:
lib/wahwah/ogg/page.rb

Overview

  1. segment_table: number_page_segments Bytes containing the lacing values of all segments in this page. Each Byte contains one lacing value.

Constant Summary collapse

HEADER_SIZE =
27
HEADER_FORMAT =
"A4CxQx12C"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file_io) ⇒ Page

Returns a new instance of Page.



106
107
108
109
110
111
112
113
114
# File 'lib/wahwah/ogg/page.rb', line 106

def initialize(file_io)
  header_content = file_io.read(HEADER_SIZE)
  @capture_pattern, @version, @granule_position, page_segments = header_content.unpack(HEADER_FORMAT) if header_content.size >= HEADER_SIZE

  return unless valid?

  segment_table = file_io.read(page_segments).unpack("C" * page_segments)
  @segments = segment_table.map { |segment_length| file_io.read(segment_length) }
end

Instance Attribute Details

#granule_positionObject (readonly)

Returns the value of attribute granule_position.



104
105
106
# File 'lib/wahwah/ogg/page.rb', line 104

def granule_position
  @granule_position
end

#segmentsObject (readonly)

Returns the value of attribute segments.



104
105
106
# File 'lib/wahwah/ogg/page.rb', line 104

def segments
  @segments
end

Instance Method Details

#valid?Boolean

Returns:

  • (Boolean)


116
117
118
# File 'lib/wahwah/ogg/page.rb', line 116

def valid?
  @capture_pattern == "OggS" && @version == 0
end