public static function trySeek($stream, $offset, $whence = SEEK_SET)
    {
        $offset = (int) $offset;

        // If SEEK_SET, we can avoid a seek if we're at the right location.
        if ($whence === SEEK_SET && ftell($stream) === $offset) {
            return true;
        }

        return static::isSeekable($stream) && fseek($stream, $offset, $whence) === 0;
    }