Pchp.Library.Streams.PhpStream.SeekInternal C# (CSharp) Method

SeekInternal() private method

Perform the actual seek on the stream. Report errors.
In case that Seek is not supported by this stream type.
private SeekInternal ( int offset, int current, SeekOrigin whence ) : bool
offset int New position in the stream.
current int Current position in the stream.
whence SeekOrigin Where to count from.
return bool
        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;
            }
        }