public override long Seek(long offset, SeekOrigin origin) { long delta = 0; // Distance between absolute cursor position and specified position in bytes if (origin.Equals(SeekOrigin.Current)) { delta = offset; } else if (origin.Equals(SeekOrigin.Begin)) { delta = offset - Position; } else if (origin.Equals(SeekOrigin.End)) { delta = (streamSize + offset) - Position; } if (0 == delta) { return(Position); } else if (delta < 0) { // If cursor is still within buffer, jump within buffer if ((cursorPosition + delta < bufferSize) && (cursorPosition + delta >= 0)) { cursorPosition += (int)delta; } else // Jump outside buffer : move the whole buffer at the beginning of the zone to read { streamPosition = bufferOffset + cursorPosition + delta; stream.Position = streamPosition; fillBuffer(); } } else if (cursorPosition + delta < bufferSize) // Jump within buffer { cursorPosition += (int)delta; } else // Jump outside buffer: move the whole buffer at the beginning of the zone to read { streamPosition = bufferOffset + cursorPosition + delta; stream.Position = streamPosition; fillBuffer(); } return(Position); }
public override long Seek(long offset, SeekOrigin origin) { if (CanSeek) { if (origin.Equals(SeekOrigin.Begin)) { Position = offset; } else if (origin.Equals(SeekOrigin.Current)) { Position += offset; } else { Position = Length - offset; } // No positin is set, we need to adjust our streams to be in the righ section. if (Position < s1.Length) { // we are in our first stream s1.Seek(Position, SeekOrigin.Begin); // If we move into stream one, then make sure to set the stream two to start reading from the beging. s2.Seek(0, SeekOrigin.Begin); } else { // We are in the second stream. // Posistion - s1.length is the relative position into stream 2. s2.Seek(Position - s1.Length, SeekOrigin.Begin); // If we are in s2, then move s1 to the end of itself. s1.Seek(0, SeekOrigin.End); } return(Position); } else { throw new NotImplementedException(); } }
public override long Seek(long offset, SeekOrigin origin) { if (CanSeek) { if (origin.Equals(SeekOrigin.Begin)) { Position = offset; } else if (origin.Equals(SeekOrigin.Current)) { Position += offset; } else { Position = Length - offset; } return(Position); } else { throw new NotImplementedException(); } }