mirror of
https://github.com/nextcloud/server.git
synced 2026-02-19 02:38:40 -05:00
fix(InMemoryFile): allow to stream read the contents
Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
This commit is contained in:
parent
6eddda147b
commit
762ae4520a
2 changed files with 14 additions and 14 deletions
|
|
@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -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()),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Reference in a new issue