def seek(self, offset, whence=SEEK_SET):
        """
        Change the stream position to the given byte offset.

        Args:
            offset: Offset is interpreted relative to the position indicated by
                whence.
            whence: The default value for whence is SEEK_SET.
                Values for whence are:
                SEEK_SET or 0 – start of the stream (the default);
                offset should be zero or positive
                SEEK_CUR or 1 – current stream position;
                offset may be negative
                SEEK_END or 2 – end of the stream;
                offset is usually negative

        Returns:
            int: The new absolute position.
        """
        if not self._seekable:
            raise UnsupportedOperation('seek')

        # Only read mode is seekable
        with self._seek_lock:
            # Set seek using raw method and
            # sync buffered seek with raw seek
            self.raw.seek(offset, whence)
            self._seek = seek = self.raw._seek

            # Preload starting from current seek
            self._preload_range()

        return seek