private bool CopySpaceIfMatched(byte[] readData, ref long readPos, long limitPos,
ref byte[] writeData, ref long writePos, byte[] searchData)
{
// Test if the byte sequence we are searching for exists in readData at the current read position:
if (BytesMatch(readData, readPos, searchData))
{
// The search sequence exists in readData at the current position.
// Test if the searched-for sequence constitutes the end of the readData:
if (limitPos - readPos >= searchData.Length)
{
// We are not at the end, so we will just copy over a space, instead of the
// readData itself:
for (long i = 0; i < m_space.Length; i++)
writeData[writePos++] = m_space[i];
// Skip past the searchData:
readPos += searchData.Length;
}
else
{
// We are at the end of the given readData, so the matching data does not
// count for anything - we will copy it over raw:
for (long i = 0; i < searchData.Length; i++)
writeData[writePos++] = readData[readPos++];
}
return true;
}
// The byte sequence was not found, so return "no work done" value:
return false;
}
}