public void RandomRead(byte[] data, int offset, int size, ulong position, bool doNotCache)
{
lock (_lock)
{
if (size > 0 && position < _writer.Ofs)
{
_stream.Position = (long)position;
var read = size;
if (_writer.Ofs - position < (ulong)read) read = (int)(_writer.Ofs - position);
if (_stream.Read(data, offset, read) != read)
throw new EndOfStreamException();
size -= read;
offset += read;
position += (ulong)read;
}
if (size == 0) return;
if ((ulong)_writer.GetCurrentPosition() < position + (ulong)size)
throw new EndOfStreamException();
Array.Copy(_writer.GetBuffer(), (int)(position - _writer.Ofs), data, offset, size);
}
}