private bool IsPreamble()
{
if (!_checkPreamble)
{
return _checkPreamble;
}
Debug.Assert(_bytePos <= _preamble.Length, "_compressPreamble was called with the current bytePos greater than the preamble buffer length. Are two threads using this StreamReader at the same time?");
int len = (_byteLen >= (_preamble.Length)) ? (_preamble.Length - _bytePos) : (_byteLen - _bytePos);
for (int i = 0; i < len; i++, _bytePos++)
{
if (_byteBuffer[_bytePos] != _preamble[_bytePos])
{
_bytePos = 0;
_checkPreamble = false;
break;
}
}
Debug.Assert(_bytePos <= _preamble.Length, "possible bug in _compressPreamble. Are two threads using this StreamReader at the same time?");
if (_checkPreamble)
{
if (_bytePos == _preamble.Length)
{
// We have a match
CompressBuffer(_preamble.Length);
_bytePos = 0;
_checkPreamble = false;
_detectEncoding = false;
}
}
return _checkPreamble;
}