Write a new file using a stream.

@param string $path
@param resource $resource
@param Config $config
@return array|false
516408
public function writeStream($path, $resource, Config $config)
    {
        $this->recursiveCreateDir(Util::dirname($path));

        $location = $this->applyPathPrefix($path);
        $stream = $this->share->write($location);

        stream_copy_to_stream($resource, $stream);

        if (!fclose($stream)) {
            return false;
        }

        return compact('path');
    }
1073863
protected function writeObject($path, $contents, Config $config)
    {
        $path = $this->applyPathPrefix($path);
        $metadata = [
            'name' => $path,
        ];

        $metadata += $this->getOptionsFromConfig($config);

        $uploadedObject = $this->bucket->upload($contents, $metadata);
        $uploadedObject->reload();

        return $this->convertObjectInfo($uploadedObject);
    }
844824
public function write($path, $contents, Config $config)
    {
        $temporaryPath = $this->createTemporaryFile($contents);

        $response = $this->cosApi->upload($this->getBucket(), $temporaryPath, $path,
            null, null, $config->get('insertOnly', 1));

        $response = $this->normalizeResponse($response);

        if (false !== $response) {
            $this->setContentType($path, $contents);
        }

        return $response;
    }
13917
public function writeStream($path, $resource, Config $config)
    {
        return $this->upload($path, $resource, $config);
    }
609819
public function updateStream($path, $resource, Config $config)
    {
        return $this->getAdapter()->updateStream($path, $resource, $config);
    }
1154246
public function update($path, $contents, array $config = []) {
        return $this->getFileSystem()->update($path, $contents, $config);
    }
634199
public static function write(string $fileName = '', $config = null): bool
    {
        $pathInfo = \pathinfo(static::normalizePath($fileName));
        if (!isset($pathInfo['extension'])) {
            $message = \sprintf(
                'Config file name "%s" is missing an extension and cannot be auto-detected',
                $pathInfo['filename']
            );

            throw new RuntimeException($message);
        }

        $extension = \strtolower($pathInfo['extension']);
        if (!\in_array($extension, static::$allowedExtensions)) {
            $message = \sprintf(
                'Unsupported config file type. Supported extension types are: %s',
                \implode(',', static::$allowedExtensions)
            );

            throw new RuntimeException($message);
        }

        if (!isset(static::$writers[$extension]) || !(static::$writers[$extension] instanceof AbstractWriter)) {
            static::$writers[$extension] = WriterManager::get($extension);
        }

        return static::$writers[$extension]->toFile($fileName, $config);
    }
1104963
public function write($path, $contents, Config $config)
    {

        // 1. Save to temporary local file -- it will be destroyed automatically
        $tempfile = tmpfile();
        fwrite($tempfile, $contents);

        // 2. Use Cloudinary to send
        $uploaded_metadata = $this->writeStream($path, $tempfile, $config);

        return $uploaded_metadata;
    }
1271307
public function put($path, $contents, array $config = [])
    {
        $path = Util::normalizePath($path);
        $config += $this->config;

        if (!$this->adapter->canOverwrite() && $this->has($path)) {
            return (bool) $this->adapter->update($path, $contents, $config);
        }

        return (bool) $this->adapter->write($path, $contents, $config);
    }
1295127
public function write($path, $contents, Config $config)
    {
        return $this->getAdapter()->write($path, $contents, $config);
    }
1131000
public function update($path, $contents, Config $config)
    {
        return $this->writeObject($path, $contents, $config);
    }
981797
public function write($path, $contents, Config $config)
    {
        $object = $this->applyPathPrefix($path);
        $options = $this->getOptions($this->options, $config);

        if (! isset($options[OssClient::OSS_LENGTH])) {
            $options[OssClient::OSS_LENGTH] = Util::contentSize($contents);
        }
        if (! isset($options[OssClient::OSS_CONTENT_TYPE])) {
            $options[OssClient::OSS_CONTENT_TYPE] = Util::guessMimeType($path, $contents);
        }
        try {
            $this->client->putObject($this->bucket, $object, $contents, $options);
        } catch (OssException $e) {
            $this->logErr(__FUNCTION__, $e);
            return false;
        }
        return $this->normalizeResponse($options, $path);
    }
242088
public function updateStream(string $path, $resource, array $config = []): bool
    {
        $location = $this->applyBasePath($path);
        $this->ensureDirectory(dirname($location));
        $stream = @fopen($location, 'w+b');

        if (! $stream) {
            return false;
        }

        stream_copy_to_stream($resource, $stream);

        if (! fclose($stream)) {
            return false;
        }

        if (($visibility = Arr::get($config, 'visibility')) !== null) {
            $this->setVisibility($path, $visibility);
        }

        unset($location, $stream, $visibility);

        return true;
    }
421440
public function updateStream($path, $resource, Config $config)
    {
        $size = Util::getStreamSize($resource);
        list($ret, $err) = Qiniu_RS_Rput($this->getClient(), $this->bucket, $path, $resource, $size, null);
        if ($err !== null) {
            return false;
        }
        return compact('size', 'path');
    }
494118
public function putStream(string $path, $resource, array $config = []): bool
    {
        $path = $this->normalizePath($path);
        $config = $this->prepareConfig($config);
        $this->rewindStream($resource);

        if (! $this->exists($path)) {
            return $this->getAdapter()->updateStream($path, $resource, $config);
        }

        return $this->getAdapter()->writeStream($path, $resource, $config);
    }
1003469
public function writeJson($path, array $config)
    {
        $jsonFile = new JsonFile($path);
        $jsonFile->write($this->prepareConfig($config));
    }
1283478
public static function fileConfig($resource)
    {
        self::$config = new Config($resource, new ConfigLoader());
        self::$config->load();
        self::$config->configure();
    }