Class: WahWah::Riff::Chunk

Inherits:
Object
  • Object
show all
Includes:
LazyRead
Defined in:
lib/wahwah/riff/chunk.rb

Overview

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.

Constant Summary collapse

HEADER_SIZE =
8
HEADER_FORMAT =
"A4V"
HEADER_TYPE_SIZE =
4

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from LazyRead

#data, prepended, #skip

Constructor Details

#initializeChunk

Returns a new instance of Chunk.



27
28
29
30
31
32
# 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).unpack1("A4") if have_type?
end

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id.



25
26
27
# File 'lib/wahwah/riff/chunk.rb', line 25

def id
  @id
end

#typeObject (readonly)

Returns the value of attribute type.



25
26
27
# File 'lib/wahwah/riff/chunk.rb', line 25

def type
  @type
end

Instance Method Details

#sizeObject



34
35
36
37
# File 'lib/wahwah/riff/chunk.rb', line 34

def size
  @size += 1 if @size.odd?
  have_type? ? @size - HEADER_TYPE_SIZE : @size
end

#valid?Boolean

Returns:

  • (Boolean)


39
40
41
# File 'lib/wahwah/riff/chunk.rb', line 39

def valid?
  !@id.empty? && !@size.nil? && @size > 0
end