diff --git a/src/SourceResource.php b/src/SourceResource.php index 9eaefdd..73f8fd0 100644 --- a/src/SourceResource.php +++ b/src/SourceResource.php @@ -21,13 +21,16 @@ public function __construct($resource) parent::__construct(); $this->onRead(static function (int $length) use (&$resource): ?string { - return fread($resource, $length) ?: null; + return (($read = fread($resource, $length)) !== '') ? + $read : + null; }); if (stream_get_meta_data($resource)['seekable']) { $this->onSeek(static function (int $offset, int $whence) use (&$resource): int { - fseek($resource, $offset, $whence); - return ftell($resource); + return fseek($resource, $offset, $whence) === 0 ? + ftell($resource) : + -1; }); } }