Beispiel #1
0
        public ChunkData(Stream stream, uint chunkSize = 0)
        {            
            Stream = stream;
            Chunks = new List<Chunk>();

            var maxRead = (uint)stream.Position + chunkSize;
            if (chunkSize == 0)
                maxRead = (uint)stream.Length;
            maxRead = Math.Min(maxRead, (uint)stream.Length);

            var br = new BinaryReader(stream);
            var baseOffset = (uint)stream.Position;
            var calcOffset = 0u;
            while ((calcOffset + baseOffset) < maxRead && (calcOffset < maxRead))
            {
                var header = new ChunkHeader(br);
                calcOffset += 8; // Add 8 bytes as we read header name + size
                Chunks.Add(new Chunk(header.Name, header.Size, calcOffset + baseOffset, stream));
                calcOffset += header.Size; // Move past the chunk

                // We seek from our current position to save some time
                if ((calcOffset + baseOffset) < maxRead && calcOffset < maxRead)
                    stream.Seek(header.Size, SeekOrigin.Current);
            }
        }
Beispiel #2
0
 public Chunk(ChunkHeader header, Stream stream)
     : this(header.Name, header.Size, (uint)stream.Position, stream)
 {
 }
Beispiel #3
0
 public Chunk(ChunkHeader header, Stream stream)
     : this(header.Name, header.Size, (uint)stream.Position, stream)
 { }