Skip to content

Commit e19666c

Browse files
Return null instead of throwing, and added test
Co-Authored-By: Frank de Jonge <[email protected]>
1 parent 7baf659 commit e19666c

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

src/Util.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -267,14 +267,14 @@ public static function isSeekableStream($resource)
267267
*
268268
* @param resource $resource
269269
*
270-
* @return int stream size
270+
* @return int|null stream size
271271
*/
272272
public static function getStreamSize($resource)
273273
{
274274
$stat = fstat($resource);
275275

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

280280
return $stat['size'];

tests/UtilTests.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,13 @@ public function testStreamSize()
170170
fclose($stream);
171171
}
172172

173+
public function testStreamSizeForUrl()
174+
{
175+
$stream = \fopen('https://flysystem.thephpleague.com/img/flysystem.svg', 'r');
176+
$this->assertNull(Util::getStreamSize($stream));
177+
fclose($stream);
178+
}
179+
173180
public function testRewindStream()
174181
{
175182
$stream = tmpfile();

0 commit comments

Comments
 (0)