public override int ReadByte()
{
// Lock down the file stream while we do this.
lock (_lock)
{
CheckSessionIsOpen();
// Setup the object for reading.
SetupRead();
// Read more data into the internal buffer if necessary.
if (_bufferPosition >= _bufferLen)
{
_bufferPosition = 0;
var data = _session.RequestRead(_handle, (ulong)_position, (uint)_readBufferSize);
_bufferLen = data.Length;
Buffer.BlockCopy(data, 0, _readBuffer, 0, _readBufferSize);
_serverFilePosition = (ulong)_position;
if (_bufferLen == 0)
{
// We've reached EOF.
return -1;
}
}
// Extract the next byte from the buffer.
++_position;
return _readBuffer[_bufferPosition++];
}
}