Skip to content

Commit

Permalink
Return null instead of throwing, and added test
Browse files Browse the repository at this point in the history
Co-Authored-By: Frank de Jonge <[email protected]>
  • Loading branch information
GrahamCampbell and frankdejonge committed Dec 29, 2019
1 parent 7baf659 commit e19666c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/Util.php
Original file line number Diff line number Diff line change
Expand Up @@ -267,14 +267,14 @@ public static function isSeekableStream($resource)
*
* @param resource $resource
*
* @return int stream size
* @return int|null stream size
*/
public static function getStreamSize($resource)
{
$stat = fstat($resource);

if ( ! is_array($stat) || ! isset($stat['size'])) {
throw new RuntimeException('Cannot stat resource. Remote files are not supported.');
return null;
}

return $stat['size'];
Expand Down
7 changes: 7 additions & 0 deletions tests/UtilTests.php
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,13 @@ public function testStreamSize()
fclose($stream);
}

public function testStreamSizeForUrl()
{
$stream = \fopen('https://flysystem.thephpleague.com/img/flysystem.svg', 'r');
$this->assertNull(Util::getStreamSize($stream));
fclose($stream);
}

public function testRewindStream()
{
$stream = tmpfile();
Expand Down

0 comments on commit e19666c

Please sign in to comment.