Class: Ogg::Page
- Inherits:
-
Object
- Object
- Ogg::Page
- Defined in:
- lib/ogginfo-rb.rb
Constant Summary collapse
- CAPTURE =
'OggS'
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#granule_position ⇒ Object
readonly
Returns the value of attribute granule_position.
-
#page_type ⇒ Object
readonly
Returns the value of attribute page_type.
-
#segment_table ⇒ Object
readonly
Returns the value of attribute segment_table.
Class Method Summary collapse
Instance Method Summary collapse
- #continues? ⇒ Boolean
-
#initialize(file) ⇒ Page
constructor
A new instance of Page.
- #next_page ⇒ Object
Constructor Details
#initialize(file) ⇒ Page
Returns a new instance of Page.
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/ogginfo-rb.rb', line 78 def initialize file @file = file # Header capture = file.read(CAPTURE.size) puts "Capture is not #{CAPTURE.inspect}" unless capture == CAPTURE version = file.read(1).unpack('C').first @page_type = file.read(1).unpack('C').first @granule_position = file.read(8).unpack('Q').first bitstream_serial_number = file.read(4).unpack('L').first page_sequence_number = file.read(4).unpack('L').first checksum = file.read(4).unpack('L').first page_segments = file.read(1).unpack('C').first @segment_table = file.read(page_segments).unpack('C*') # Content @data = StringIO.new '', 'w+' @segment_table.each do |n| @data.write file.read(n) end @data.close_write @data.rewind end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
75 76 77 |
# File 'lib/ogginfo-rb.rb', line 75 def data @data end |
#granule_position ⇒ Object (readonly)
Returns the value of attribute granule_position.
76 77 78 |
# File 'lib/ogginfo-rb.rb', line 76 def granule_position @granule_position end |
#page_type ⇒ Object (readonly)
Returns the value of attribute page_type.
76 77 78 |
# File 'lib/ogginfo-rb.rb', line 76 def page_type @page_type end |
#segment_table ⇒ Object (readonly)
Returns the value of attribute segment_table.
76 77 78 |
# File 'lib/ogginfo-rb.rb', line 76 def segment_table @segment_table end |
Class Method Details
.find_last_page(file) ⇒ Object
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 |
# File 'lib/ogginfo-rb.rb', line 121 def self.find_last_page file buffer_size = 1024 pos = file.stat.size - buffer_size while pos > 0 file.seek pos, IO::SEEK_SET sio = StringIO.new file.read(buffer_size) # Find last page in buffer pg = page = Page.find_page(sio) while pg page = pg pg = pg.next_page end return page if page pos -= buffer_size * 2 - (CAPTURE.size - 1) end # This means that the Ogg file is not valid return nil end |