System.IO.FileStream.FlushReadBuffer C# (CSharp) Method

FlushReadBuffer() private method

Dumps any read data in the buffer and rewinds our position in the stream, accordingly, as necessary.
private FlushReadBuffer ( ) : void
return void
        private void FlushReadBuffer()
        {
            // Reading is done by blocks from the file, but someone could read
            // 1 byte from the buffer then write.  At that point, the OS's file
            // pointer is out of sync with the stream's position.  All write 
            // functions should call this function to preserve the position in the file.

            AssertBufferInvariants();
            Debug.Assert(_writePos == 0, "FileStream: Write buffer must be empty in FlushReadBuffer!");

            int rewind = _readPos - _readLength;
            if (rewind != 0)
            {
                Debug.Assert(CanSeek, "FileStream will lose buffered read data now.");
                SeekCore(rewind, SeekOrigin.Current);
            }
            _readPos = _readLength = 0;
        }