public static RiffChunk Parse(BinaryReader reader) { var chunk = new RiffChunk { ChunkId = Utils.ReadUTF8String(reader, 4), Size = reader.ReadInt32(), Type = Utils.ReadUTF8String(reader, 4) }; if (chunk.ChunkId != "RIFF") { throw new InvalidDataException("Not a valid RIFF file"); } return(chunk); }
public void ParseRiff(Stream file) { using (BinaryReader reader = new BinaryReader(file)) { RiffChunk = RiffChunk.Parse(reader); SubChunks.Clear(); // Size is counted from after the ChunkSize field, not the RiffType field long startOffset = reader.BaseStream.Position - 4; long endOffset = startOffset + RiffChunk.Size; // Make sure 8 bytes are available for the subchunk header while (reader.BaseStream.Position + 8 < endOffset) { RiffSubChunk subChunk = ParseSubChunk(reader); SubChunks[subChunk.SubChunkId] = subChunk; } } }