Class: WahWah::Riff::Chunk
- Inherits:
-
Object
- Object
- WahWah::Riff::Chunk
- 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
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
-
#initialize ⇒ Chunk
constructor
A new instance of Chunk.
- #size ⇒ Object
- #valid? ⇒ Boolean
Methods included from LazyRead
Constructor Details
#initialize ⇒ Chunk
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
#id ⇒ Object (readonly)
Returns the value of attribute id.
25 26 27 |
# File 'lib/wahwah/riff/chunk.rb', line 25 def id @id end |
#type ⇒ Object (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
#size ⇒ Object
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
39 40 41 |
# File 'lib/wahwah/riff/chunk.rb', line 39 def valid? @id && !@id.empty? && !@size.nil? && @size > 0 end |