thephpleague / flysystem-rackspace

Flysystem Adapter for Rackspace
37 stars 28 forks source link

readStream() returns empty string #13

Closed elpiel closed 8 years ago

elpiel commented 8 years ago

So I am using Rackspace with my Symfony2 project, The problem occurs when I want to read from stream:

$filesystem = $this->container->get('oneup_flysystem.XXXX_filesystem');
// Retrieve a read-stream
$stream = $filesystem->readStream('63335b4af21bf2f76145e21b1130570d2356b274.jpg');
$contents = stream_get_contents($stream);
if(is_resource($stream))
{
      fclose($stream);
}
var_dump($contents);

The file is there, the $contents is shown as empty string. When I change readStream() to read(), it dumps all the data of the jpg file, but no data with readStream(). Any idea why?

PS: As per documentation in php.net, if stream_get_contents fails it will return FALSE not empty string. Also note that writeStream() works just fine...

frankdejonge commented 8 years ago

@twify93 this is very odd, the adapter implementation for is super straight forward. Perhaps you can check if the resource needs to be rewind'ed before getting the contents? This could give us a clue and a possible fix.

elpiel commented 8 years ago

@frankdejonge Yes indeed, this was the problem, but why is this issue here? I haven't read the stream and I can't find if the Adapter does it, it just gives the resource?

frankdejonge commented 8 years ago

@twify93 it might be a bug in the SDK. I'll push a fix for this just in case.

frankdejonge commented 8 years ago

version 1.0.4 is tagged which has this fix.