Class: Riff::RiffReaderChunk

Inherits:
Object
  • Object
show all
Defined in:
lib/ruck/misc/riff.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(fn, start) ⇒ RiffReaderChunk

Returns a new instance of RiffReaderChunk.



17
18
19
20
21
22
# File 'lib/ruck/misc/riff.rb', line 17

def initialize(fn, start)
  @fn, @start = fn, start
  @size_start = @start + 4
  @data_start = @start + 8
  @data_skip = 0
end

Instance Attribute Details

#data_skipObject

Returns the value of attribute data_skip.



15
16
17
# File 'lib/ruck/misc/riff.rb', line 15

def data_skip
  @data_skip
end

#data_startObject (readonly)

Returns the value of attribute data_start.



14
15
16
# File 'lib/ruck/misc/riff.rb', line 14

def data_start
  @data_start
end

Instance Method Details

#[](*args) ⇒ Object

pass a Range of bytes, or start and length



42
43
44
45
46
47
48
49
50
51
# File 'lib/ruck/misc/riff.rb', line 42

def [](*args)
  return if @fn.closed?
  
  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

#chunksObject



53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/ruck/misc/riff.rb', line 53

def chunks
  return @chunks if @chunks
  return [] if @fn.closed?
  
  offset = @data_start + @data_skip
  @chunks = []
  while offset + @data_skip - @data_start < size
    chunk = RiffReaderChunk.new(@fn, offset)
    @chunks << chunk
    offset += @data_start + chunk.size
  end
  
  @chunks
end

#sizeObject



32
33
34
35
36
37
38
39
# File 'lib/ruck/misc/riff.rb', line 32

def size
  return @size - @data_skip if @size
  return nil if @fn.closed?
  
  @fn.seek @size_start
  @size = @fn.read(4).unpack("L")[0]
  @size - @data_skip
end

#to_sObject



68
69
70
# File 'lib/ruck/misc/riff.rb', line 68

def to_s
  "<RiffHeader type:#{type} size:#{size}>"
end

#typeObject



24
25
26
27
28
29
30
# File 'lib/ruck/misc/riff.rb', line 24

def type
  return @type if @type
  return nil if @fn.closed?
  
  @fn.seek @start
  @type = @fn.read(4)
end