Class: IFF::FORM

Inherits:
Base
  • Object
show all
Defined in:
lib/iff.rb

Direct Known Subclasses

CAT, LIST, PROP, RIFF

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

iff_tag

Constructor Details

#initialize(tag, chunks) ⇒ FORM

Returns a new instance of FORM.



206
207
208
209
# File 'lib/iff.rb', line 206

def initialize( tag, chunks )
  @tag = tag
  @chunks = chunks.to_a.dup
end

Instance Attribute Details

#tagObject (readonly)

Returns the value of attribute tag.



189
190
191
# File 'lib/iff.rb', line 189

def tag
  @tag
end

#typeObject (readonly)

Returns the value of attribute type.



190
191
192
# File 'lib/iff.rb', line 190

def type
  @type
end

Class Method Details

.unserialize(tag, length, stream, options) ⇒ Object

Raises:

  • (EOFError)


192
193
194
195
196
197
198
199
200
201
202
203
204
# File 'lib/iff.rb', line 192

def self.unserialize( tag, length, stream, options )
  raise EOFError, "Premature end of content" if length < 4
  type = stream.read( 4 )
  raise EOFError, "Premature end of content" if type.length < 4
  parser = Parser.new( stream, length, options )
  chunks = []
  loop do
    chunk = parser.parse
    break unless chunk
    chunks << chunk
  end
  self.new( tag, chunks )
end

Instance Method Details

#chunksObject



211
# File 'lib/iff.rb', line 211

def chunks ; @chunks.dup ; end

#chunks=(chunks) ⇒ Object



212
# File 'lib/iff.rb', line 212

def chunks=( chunks ) ; @chunks = chunks.to_a.dup ; end

#serialize(stream, options) ⇒ Object



214
215
216
217
218
219
220
# File 'lib/iff.rb', line 214

def serialize( stream, options )
  stream << [ self.type ].pack( "a4" )
  emitter = Emitter.new( stream, options )
  @chunks.each do |chunk|
    emitter.emit( chunk )
  end
end