Class: Riff::RiffReaderChunk
Instance Attribute Summary collapse
-
#data_skip ⇒ Object
Returns the value of attribute data_skip.
-
#data_start ⇒ Object
readonly
Returns the value of attribute data_start.
Instance Method Summary collapse
-
#[](*args) ⇒ Object
pass a Range of bytes, or start and length.
- #chunks ⇒ Object
-
#initialize(fn, start) ⇒ RiffReaderChunk
constructor
A new instance of RiffReaderChunk.
- #size ⇒ Object
- #to_s ⇒ Object
- #type ⇒ Object
Constructor Details
#initialize(fn, start) ⇒ RiffReaderChunk
Returns a new instance of RiffReaderChunk.
8 9 10 11 12 13 |
# File 'lib/ruck/misc/riff.rb', line 8 def initialize(fn, start) @fn, @start = fn, start @size_start = @start + 4 @data_start = @start + 8 @data_skip = 0 end |
Instance Attribute Details
#data_skip ⇒ Object
Returns the value of attribute data_skip.
6 7 8 |
# File 'lib/ruck/misc/riff.rb', line 6 def data_skip @data_skip end |
#data_start ⇒ Object (readonly)
Returns the value of attribute data_start.
5 6 7 |
# File 'lib/ruck/misc/riff.rb', line 5 def data_start @data_start end |
Instance Method Details
#[](*args) ⇒ Object
pass a Range of bytes, or start and length
29 30 31 32 33 34 35 36 |
# File 'lib/ruck/misc/riff.rb', line 29 def [](*args) first, last = case args.length when 1; [args.first.begin, args.first.end] when 2; [args[0], args[0] + args[1]] end @fn.seek @data_start + @data_skip + first @fn.read(last - first + 1) end |
#chunks ⇒ Object
38 39 40 41 42 43 44 45 46 |
# File 'lib/ruck/misc/riff.rb', line 38 def chunks offset = @data_start + @data_skip chunks = [] while offset + @data_skip - @data_start < size chunks << chunk = RiffReaderChunk.new(@fn, offset) offset += @data_start + chunk.size end chunks end |
#size ⇒ Object
21 22 23 24 25 26 |
# File 'lib/ruck/misc/riff.rb', line 21 def size return @size - @data_skip if @size @fn.seek @size_start @size = @fn.read(4).unpack("L")[0] @size - @data_skip end |
#to_s ⇒ Object
48 49 50 |
# File 'lib/ruck/misc/riff.rb', line 48 def to_s "<RiffHeader type:#{type} size:#{size}>" end |
#type ⇒ Object
15 16 17 18 19 |
# File 'lib/ruck/misc/riff.rb', line 15 def type return @type if @type @fn.seek @start @type = @fn.read(4) end |