internal bool SeekInternal(int offset, int current, SeekOrigin whence)
{
try
{
if (!CanSeek)
{
PhpException.Throw(PhpError.Warning, ErrResources.wrapper_op_unsupported, "Seek");
return false;
}
if (!RawSeek(offset, whence)) return false;
int expectedOffset = 0, absoluteOffset = RawTell();
switch (whence)
{
case SeekOrigin.Begin:
expectedOffset = offset;
break;
case SeekOrigin.Current:
expectedOffset = current + offset;
break;
case SeekOrigin.End:
expectedOffset = RawLength() + offset;
break;
default:
PhpException.Throw(PhpError.Warning, ErrResources.invalid_argument_value, "whence", whence.ToString());
return false;
}
readOffset = writeOffset = absoluteOffset;
// No data should be buffered when seeking the underlying stream!
Debug.Assert(readBuffers == null);
Debug.Assert(writeBuffer == null || writePosition == 0);
readPosition = writePosition = 0;
// EX: This is inaccurate, but there is no better information avalable (w/o processing the whole stream)
readFilteredCount = readOffset;
writeFilteredCount = readOffset;
return absoluteOffset == expectedOffset;
// Seek is successful if the two values match.
}
catch (System.Exception)
{
PhpException.Throw(PhpError.Warning, ErrResources.wrapper_op_unsupported, "Seek");
return false;
}
}