public int Read(sbyte[] toRead, int offset, int length)
{
// Read
int currentByte = 0;
bool canReadStream = true;
while (currentByte < length && canReadStream)
{
if (NumForwardBytesInBuffer > 0)
{ // from mem
NumForwardBytesInBuffer--;
toRead[offset + currentByte] = (sbyte)COB[NumForwardBytesInBuffer];
currentByte++;
}
else
{ // from stream
int newBytes = length - currentByte;
int numRead = S.Read(Temp, 0, newBytes);
canReadStream = numRead >= newBytes;
for (int i = 0; i < numRead; i++)
{
COB.Push(Temp[i]);
toRead[offset + currentByte + i] = (sbyte)Temp[i];
}
currentByte += numRead;
}
}
return(currentByte);
}