private int ReadInner(byte[] buff, int offset, int count, int blockIdx, int blockOffset)
{
// Determine how many bytes will be read (based on requested bytes versus the number available).
int readCount = Math.Min(count, _length - _position);
if(0 == readCount) {
return 0;
}
int remaining = readCount;
int tgtOffset = offset;
int blkIdx = blockIdx;
int blkOffset = blockOffset;
for(;;)
{
// Get handle on target block.
byte[] blk = _blockList[blkIdx];
// Determine how many bytes to write into this block.
int copyCount = Math.Min(_blockSize - blkOffset, remaining);
// Write bytes into the buffer.
Array.Copy(blk, blkOffset, buff, tgtOffset, copyCount);
// Test for completion.
remaining -= copyCount;
if(0 == remaining)
{ // All bytes have been copied.
break;
}
// Update state.
tgtOffset += copyCount;
blkIdx++;
blkOffset++;
blkOffset = 0;
}
_position += readCount;
return readCount;
}