NVorbis.StreamReadBuffer.PrepareStreamForRead C# (CSharp) Method

PrepareStreamForRead() private method

private PrepareStreamForRead ( int readCount, long readOffset ) : int
readCount int
readOffset long
return int
        int PrepareStreamForRead(int readCount, long readOffset)
        {
            if (readCount > 0 && _wrapper.Source.Position != readOffset)
            {
                if (readOffset < _wrapper.EofOffset)
                {
                    if (_wrapper.Source.CanSeek)
                    {
                        _wrapper.Source.Position = readOffset;
                    }
                    else
                    {
                        // ugh, gotta read bytes until we've reached the desired offset
                        var seekCount = readOffset - _wrapper.Source.Position;
                        if (seekCount < 0)
                        {
                            // not so fast... we can't seek backwards.  This technically shouldn't happen, but just in case...
                            readCount = 0;
                        }
                        else
                        {
                            while (--seekCount >= 0)
                            {
                                if (_wrapper.Source.ReadByte() == -1)
                                {
                                    // crap... we just threw away a bunch of bytes for no reason
                                    _wrapper.EofOffset = _wrapper.Source.Position;
                                    readCount = 0;
                                    break;
                                }
                            }
                        }
                    }
                }
                else
                {
                    readCount = 0;
                }
            }
            return readCount;
        }