Use fstat to read the size of the resource in Stream

This commit is contained in:
PJ Dietz 2015-04-07 20:10:20 -04:00
parent 5cc259944e
commit cbeadbda53
2 changed files with 4 additions and 3 deletions

View File

@ -68,7 +68,8 @@ class Stream implements StreamableInterface
*/
public function getSize()
{
return null;
$statistics = fstat($this->handle);
return $statistics["size"] ?: null;
}
/**

View File

@ -108,10 +108,10 @@ class StreamTest extends \PHPUnit_Framework_TestCase
* @covers WellRESTed\Stream\Stream::getSize
* @uses WellRESTed\Stream\Stream
*/
public function testReturnsNullForSize()
public function testReturnsSize()
{
$stream = new Stream($this->handle);
$this->assertNull($stream->getSize());
$this->assertEquals(strlen($this->content), $stream->getSize());
}
/**