class WahWah::Riff::Chunk

4 bytes: an ASCII identifier for this particular RIFF or LIST chunk (for RIFF in the typical case, these 4 bytes describe the content of the entire file, such as “AVI ” or “WAVE”). rest of data: subchunks.

Constants

HEADER_FORMAT
HEADER_SIZE
HEADER_TYPE_SIZE

Attributes

id[R]
type[R]

Public Class Methods

new() click to toggle source
# File lib/wahwah/riff/chunk.rb, line 27
def initialize
  @id, @size = @file_io.read(HEADER_SIZE)&.unpack(HEADER_FORMAT)
  return unless valid?

  @type = @file_io.read(HEADER_TYPE_SIZE).unpack('A4').first if have_type?
end

Public Instance Methods

size() click to toggle source
# File lib/wahwah/riff/chunk.rb, line 34
def size
  @size = @size + 1 if @size.odd?
  have_type? ? @size - HEADER_TYPE_SIZE : @size
end
valid?() click to toggle source
# File lib/wahwah/riff/chunk.rb, line 39
def valid?
  !@id.empty? && !@size.nil? && @size > 0
end

Private Instance Methods

have_type?() click to toggle source
# File lib/wahwah/riff/chunk.rb, line 44
def have_type?
  %w(RIFF LIST).include? @id
end