From e19666cf7703de1fa2a58d624448c04e29ea0d17 Mon Sep 17 00:00:00 2001 From: Graham Campbell Date: Sun, 29 Dec 2019 14:41:16 +0000 Subject: [PATCH] Return null instead of throwing, and added test Co-Authored-By: Frank de Jonge --- src/Util.php | 4 ++-- tests/UtilTests.php | 7 +++++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/Util.php b/src/Util.php index c1e9fc395..76454a05e 100644 --- a/src/Util.php +++ b/src/Util.php @@ -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']; diff --git a/tests/UtilTests.php b/tests/UtilTests.php index 83642bfb4..fc8875841 100644 --- a/tests/UtilTests.php +++ b/tests/UtilTests.php @@ -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();