Class: Riff::Reader::Chunk
- Inherits:
-
Object
- Object
- Riff::Reader::Chunk
- Defined in:
- lib/riff/reader.rb
Overview
The Chunk object represents a chunk of a larger RIFF file. The chunk may be interrogated to reveal its fourcc and the size of its body. The chunk also provides the body
method to access the stream of data within the chunk. Keep in mind that this bit of data can be very, very large in media files (like .wav files) and that reading them in a language like ruby will be quite slow.
Instance Attribute Summary collapse
-
#fourcc ⇒ Object
readonly
the four-character code of this chunk, always four characters long (shorter fourcc’s are padded with spaces).
-
#length ⇒ Object
readonly
the length of the body of the chunk (the length of the chunk minus the the fourcc and length bytes; thus the length of the chunk - 8) This data is read directly from the chunk’s preamble and calling this is much, much faster than body.size.
-
#offset ⇒ Object
readonly
the offset of this chunk from the start of its file.
Class Method Summary collapse
-
.read_chunk(fp) ⇒ Object
:nodoc:.
Instance Method Summary collapse
-
#body ⇒ Object
Reads the entire body of the chunk (all of the data following the fourcc and size).
-
#each_byte ⇒ Object
Yields each byte of the data chunk.
-
#is_list? ⇒ Boolean
Returns
true
if this object is a ListChunk.
Instance Attribute Details
#fourcc ⇒ Object (readonly)
the four-character code of this chunk, always four characters long (shorter fourcc’s are padded with spaces)
124 125 126 |
# File 'lib/riff/reader.rb', line 124 def fourcc @fourcc end |
#length ⇒ Object (readonly)
the length of the body of the chunk (the length of the chunk minus the the fourcc and length bytes; thus the length of the chunk - 8) This data is read directly from the chunk’s preamble and calling this is much, much faster than body.size
130 131 132 |
# File 'lib/riff/reader.rb', line 130 def length @length end |
#offset ⇒ Object (readonly)
the offset of this chunk from the start of its file
133 134 135 |
# File 'lib/riff/reader.rb', line 133 def offset @offset end |
Class Method Details
Instance Method Details
#body ⇒ Object
Reads the entire body of the chunk (all of the data following the fourcc and size)
147 148 149 150 |
# File 'lib/riff/reader.rb', line 147 def body @file.pos = @offset + 8 @file.read @length end |
#each_byte ⇒ Object
Yields each byte of the data chunk.
159 160 161 162 163 |
# File 'lib/riff/reader.rb', line 159 def each_byte while @file.pos < @offset + 8 + @length yield @file.getc end end |