public override long Seek(long offset, SeekOrigin origin)
{
int nextChunk;
long nextPosition = 0L;
switch (origin)
{
case SeekOrigin.Begin:
nextPosition = Math.Min(offset, _fileInfo.Length);
break;
case SeekOrigin.Current:
nextPosition = Math.Min(_position + offset, _fileInfo.Length);
break;
case SeekOrigin.End:
nextPosition = Math.Min(_fileInfo.Length + offset, _fileInfo.Length);
break;
}
nextChunk = (int)(nextPosition / _fileInfo.ChunkSize);
if (nextChunk != _currentIndex)
{
LoadChunk(nextChunk);
_currentIndex = nextChunk;
}
var boffset = nextPosition % _fileInfo.ChunkSize;
_buffer.Position = boffset;
_position = nextPosition;
return _position;
}