I am currently in the process of writing a BinaryReader that caches the BaseStream.Position
and BaseStream.Length
properties. Here is what I have so far:
public class FastBinaryReader
{
BinaryReader reader;
public long Length { get; private set; }
public long Position { get; private set; }
public FastBinaryReader(Stream stream)
{
reader = new BinaryReader(stream);
Length = stream.Length;
Position = 0;
}
public void Seek(long newPosition)
{
reader.BaseStream.Position = newPosition;
Position = newPosition;
}
public byte[] ReadBytes(int count)
{
if (Position + count >= Length)
Position = Length;
else
Position += count;
return reader.ReadBytes(count);
}
public void Close()
{
reader.Close();
}
}
Instead of providing a Length
and Position
property, I would like to create a BaseStream
property that allows me to expose my Position
and Length
properties as FastBinaryReader.BaseStream.Position
and FastBinaryReader.BaseStream.Length
, so that my existing code will stay compatible with the original BinaryReader
class.
How would I go about doing this?