in binding/SkiaSharp/SKFrontBufferedStream.cs [63:104]
public override int Read(byte[] buffer, int offset, int count)
{
var start = currentOffset;
if (internalBuffer == null && currentOffset < totalBufferSize)
{
// create the buffer now, since we are going to be writing to it
internalBuffer = new byte[totalBufferSize];
}
// try read any data from the buffer
if (currentOffset < bufferedSoFar)
{
var bytesCopied = ReadFromBuffer(buffer, offset, count);
count -= bytesCopied;
offset += bytesCopied;
}
// read from the stream and buffer that
if (count > 0 && bufferedSoFar < totalBufferSize)
{
var buffered = BufferAndWriteTo(buffer, offset, count);
count -= buffered;
offset += buffered;
}
// just read from the stream
if (count > 0)
{
var direct = ReadDirectlyFromStream(buffer, offset, count);
count -= direct;
offset += direct;
if (direct > 0)
{
// if we are here, we are past the buffer and can't go back
internalBuffer = null;
}
}
return (int)(currentOffset - start);
}