Class: IFF::Parser
Instance Method Summary collapse
-
#initialize(stream, length = nil, options = {}) ⇒ Parser
constructor
A new instance of Parser.
- #parse ⇒ Object
Methods included from ParserEmitterCommon
Constructor Details
#initialize(stream, length = nil, options = {}) ⇒ Parser
Returns a new instance of Parser.
128 129 130 131 |
# File 'lib/iff.rb', line 128 def initialize( stream, length=nil, ={} ) super( stream, ) @length = length end |
Instance Method Details
#parse ⇒ Object
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 |
# File 'lib/iff.rb', line 133
def parse
if @length
return nil if @length.zero?
raise EOFError, "Premature end of IFF header" \
if @length < HEADER_LENGTH
end
header = @stream.read( HEADER_LENGTH )
unless header
if @length && @length.nonzero?
raise EOFError, "More chunks expected"
else
return nil
end
end
raise EOFError, "Premature end of IFF header" \
if header.length < HEADER_LENGTH
( tag, length ) = header.unpack( @header_format )
raise EOFError, "Body too short" \
if @length && @length < length
factory = IFF.get_type( tag )
if !factory && @options[:skip_unknown]
length += 1 if padding_required_for? length
skip_bytes( length )
retry
end
factory ||= Chunk
chunk = factory.unserialize( tag, length, @stream, @options )
@length -= length if @length
skip_bytes( 1 ) if padding_required_for? length
chunk
end
|