The BetterStreams Class Library
ReadBehind Property
Namespaces > BetterStreams > BetterBufferedStream > ReadBehind
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.
Syntax
C#Visual BasicManaged C++
public virtual int ReadBehind { get; set; }
Public Overridable Property ReadBehind As Integer
public:
virtual property int ReadBehind {
	int get ();
	void set (int value);
}
Remarks

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.

Examples
CopyC#
//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();
Exceptions
ExceptionCondition
ArgumentOutOfRangeExceptionReadBehind is greater than the size of the buffer - 1
ObjectDisposedExceptionThe BetterBufferedStream has already been closed.

Assembly: BetterStreams (Module: BetterStreams) Version: 1.0.0.0