Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

StreamWrapper, write called twice #626

Open
JoniJnm opened this issue Oct 17, 2019 · 0 comments
Open

StreamWrapper, write called twice #626

JoniJnm opened this issue Oct 17, 2019 · 0 comments
Assignees

Comments

@JoniJnm
Copy link

JoniJnm commented Oct 17, 2019

I was testing with google cloud storage and seems that content is uploaded twice using StreamWrapper.

The test:

<?php

use Gaufrette\Adapter\GoogleCloudStorage;
use Gaufrette\Filesystem;
use Gaufrette\StreamWrapper;

require_once(__DIR__ . '/../vendor/autoload.php');

const AUTH_FILE = './google-cloud.json';
const BUCKET_NAME = 'testing';
const LOCAL_FILE = __DIR__.'/test.txt';

// Create filesystem
$googleClient = new \Google_Client();
$googleClient->setAuthConfig(AUTH_FILE);
$googleClient->addScope(\Google_Service_Storage::DEVSTORAGE_FULL_CONTROL);
$service = new \Google_Service_Storage($googleClient);
$adapter = new class($service, BUCKET_NAME) extends GoogleCloudStorage
{
    public function write($key, $content)
    {
        echo 'write strlen ' . strlen($content) . PHP_EOL;

        return parent::write($key, $content);
    }
};
$filesystem = new Filesystem($adapter);

// Register wrapper
$map = StreamWrapper::getFilesystemMap();
$map->set(BUCKET_NAME, $filesystem);

StreamWrapper::register();

// Upload file
copy(LOCAL_FILE, 'gaufrette://' . BUCKET_NAME . '/test.txt');

The output is:

jnunez@xxx:~$ php ./test.php
write strlen 0
write strlen 5
write strlen 5

Changing

copy(LOCAL_FILE, 'gaufrette://' . BUCKET_NAME . '/test.txt');

by

$filesystem->write('/test.txt', file_get_contents(LOCAL_FILE));

The output is:

jnunez@xxx:~$ php ./test.php
write strlen 5

Is there a bug?

@JoniJnm JoniJnm changed the title StreamWrapper, write call twice StreamWrapper, write called twice Oct 17, 2019
@PedroTroller PedroTroller self-assigned this Apr 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants