diff --git a/lib/public/Files/SimpleFS/InMemoryFile.php b/lib/public/Files/SimpleFS/InMemoryFile.php index 7849b8c879a..d5a0fa160cb 100644 --- a/lib/public/Files/SimpleFS/InMemoryFile.php +++ b/lib/public/Files/SimpleFS/InMemoryFile.php @@ -105,7 +105,7 @@ class InMemoryFile implements ISimpleFile { } /** - * {@inheritDoc} + * @inheritDoc * @since 24.0.0 */ public function getExtension(): string { @@ -113,15 +113,15 @@ class InMemoryFile implements ISimpleFile { } /** - * Stream reading is unsupported for in memory files. - * - * @throws NotPermittedException + * @inheritDoc * @since 16.0.0 + * @since 34.0.0 - return in-memory stream of contents */ public function read() { - throw new NotPermittedException( - 'Stream reading is unsupported for in memory files' - ); + $stream = fopen('php://memory', 'r+'); + fwrite($stream, $this->contents); + rewind($stream); + return $stream; } /** diff --git a/tests/lib/Files/SimpleFS/InMemoryFileTest.php b/tests/lib/Files/SimpleFS/InMemoryFileTest.php index 62f3c86bb78..25f0a4a4d03 100644 --- a/tests/lib/Files/SimpleFS/InMemoryFileTest.php +++ b/tests/lib/Files/SimpleFS/InMemoryFileTest.php @@ -4,7 +4,7 @@ declare(strict_types=1); /** * SPDX-FileCopyrightText: 2018 Nextcloud GmbH and Nextcloud contributors - * SPDX-License-Identifier: AGPL-3.0-only + * SPDX-License-Identifier: AGPL-3.0-or-later */ namespace Test\File\SimpleFS; @@ -14,7 +14,7 @@ use OCP\Files\SimpleFS\InMemoryFile; use Test\TestCase; /** - * This class provide test casesf or the InMemoryFile. + * This class provide test cases for the InMemoryFile. * * @package Test\File\SimpleFS */ @@ -106,13 +106,13 @@ class InMemoryFileTest extends TestCase { /** - * Asserts that read() raises an NotPermittedException. - * - * @return void + * Ensure that read() returns a stream with the same contents than the original file. */ public function testRead(): void { - self::expectException(NotPermittedException::class); - $this->testPdf->read(); + self::assertEquals( + file_get_contents(__DIR__ . '/../../../data/test.pdf'), + stream_get_contents($this->testPdf->read()), + ); } /**