Пример #1
0
        public static RiffChunk Parse(BinaryReader reader)
        {
            var chunk = new RiffChunk
            {
                ChunkId = reader.ReadUTF8(4),
                Size    = reader.ReadInt32(),
                Type    = reader.ReadUTF8(4)
            };

            if (chunk.ChunkId != "RIFF")
            {
                throw new InvalidDataException("Not a valid RIFF file");
            }

            return(chunk);
        }
Пример #2
0
        public void ParseRiff(Stream file)
        {
            using (BinaryReader reader = GetBinaryReader(file, Endianness.LittleEndian))
            {
                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;
                }
            }
        }