// Copy up to length of bytes from input directly.
// This is used for uncompressed block.
public int CopyFrom(InputBuffer input, int length)
{
length = Math.Min(Math.Min(length, WindowSize - _bytesUsed), input.AvailableBytes);
int copied;
// We might need wrap around to copy all bytes.
int tailLen = WindowSize - _end;
if (length > tailLen)
{
// copy the first part
copied = input.CopyTo(_window, _end, tailLen);
if (copied == tailLen)
{
// only try to copy the second part if we have enough bytes in input
copied += input.CopyTo(_window, 0, length - tailLen);
}
}
else
{
// only one copy is needed if there is no wrap around.
copied = input.CopyTo(_window, _end, length);
}
_end = (_end + copied) & WindowMask;
_bytesUsed += copied;
return(copied);
}