Class: Riff::Reader::ListChunk

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/riff/reader.rb

Overview

ListChunk is a subclass of Chunk, and so you can access its fourcc and size

Note: The body method is not permitted on ListChunk

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#signatureObject (readonly)

The four-character signature of the container chunk.

In the case of a RIFF WAV container, this is “WAVE”



185
186
187
# File 'lib/riff/reader.rb', line 185

def signature
  @signature
end

Instance Method Details

#[](chunk_spec) ⇒ Object

Accesses the chunks of the file by either a fourcc, an index, or a range. Be aware that ListChunks may contain many children chunk with the same fourcc, so using the index will always get you a paticular one, while using the fourcc will only get you the first of a class.



191
192
193
194
195
196
197
198
199
# File 'lib/riff/reader.rb', line 191

def [](chunk_spec) # :return: array or Chunk
  if chunk_spec.instance_of? String then
    detect {|chunk| chunk.fourcc == "%s" % [ chunk_spec ] }
  elsif chunk_spec.instance_of? Fixnum or chunk_spec.instance_of? Range then
    to_a[chunk_spec]
  else
    raise ArgumentError , "ListChunk#[] may only accept a String, Fixnum, or Range"
  end
end

#eachObject

Yields each chunk in the order it appears in the file



202
203
204
205
206
207
208
209
# File 'lib/riff/reader.rb', line 202

def each # :yields: chunk
  @file.pos = @offset + 12
  while @file.eof? == false && @file.pos < @offset + 8 + @length
    a_chunk = Chunk.read_chunk(@file)
    yield a_chunk
    @file.pos = a_chunk.offset + 8 + a_chunk.length + (a_chunk.length % 2 == 0 ? 0 : 1)
  end
end