When filling the buffer for reading, this number of bytes from before
the current stream position will be cached. This will improve efficiency
if you frequently seek backwards by this number of bytes
or fewer.
After all the bytes in the internal buffer have been read, the BetterBufferedStream must refill it from the underlying stream. When doing so, it can optionally cache ReadBehind bytes from before the current stream position rather than simply buffering only bytes at the current position and later. This may be useful when you frequently seek backwards a few bytes in the stream (for example, when "peeking" at the next few bytes); otherwise, set this property to 0.
//assume we have a stream "stream" that we can read from //we create a BetterBufferedStream with a ReadBehind of 1 BetterBufferedStream bufferedStream = new BetterBufferedStream(stream,100,1,false); //...do something... //now we can always "peek" at the next byte efficiently, since even if the next byte //requires the buffer to be refilled the previous byte will still be buffered: bufferedStream.ReadByte(); //read a byte bufferedStream.Position -= 1; //return bufferedStream to the state it was in prior to reading the byte //...do something else... bufferedStream.Close();
| Exception | Condition |
|---|---|
| ArgumentOutOfRangeException | ReadBehind is greater than the size of the buffer - 1 |
| ObjectDisposedException | The BetterBufferedStream has already been closed. |