summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMorris Jobke <hey@morrisjobke.de>2018-07-11 13:40:09 +0200
committerGitHub <noreply@github.com>2018-07-11 13:40:09 +0200
commit229289d206c954baede095e2bae2f34915471a44 (patch)
tree83c84f12efb8733af4fc5793969054a93210dc7d
parent8ccb99f4167919ccda5902aed60ce81c7d597d1d (diff)
parent6da2b7c4f6744baa5a14a2919790d034de4229bf (diff)
downloadnextcloud-server-229289d206c954baede095e2bae2f34915471a44.tar.gz
nextcloud-server-229289d206c954baede095e2bae2f34915471a44.zip
Merge pull request #10122 from nextcloud/feature/noid/appdata-fopen-stream
Add fopen method to ISimpleFile
-rw-r--r--lib/private/Files/SimpleFS/SimpleFile.php23
-rw-r--r--lib/public/Files/SimpleFS/ISimpleFile.php18
-rw-r--r--tests/lib/Files/SimpleFS/SimpleFileTest.php16
3 files changed, 57 insertions, 0 deletions
diff --git a/lib/private/Files/SimpleFS/SimpleFile.php b/lib/private/Files/SimpleFS/SimpleFile.php
index e9bf0213d07..7b83e9372f7 100644
--- a/lib/private/Files/SimpleFS/SimpleFile.php
+++ b/lib/private/Files/SimpleFS/SimpleFile.php
@@ -146,4 +146,27 @@ class SimpleFile implements ISimpleFile {
public function getMimeType() {
return $this->file->getMimeType();
}
+
+ /**
+ * Open the file as stream for reading, resulting resource can be operated as stream like the result from php's own fopen
+ *
+ * @return resource
+ * @throws \OCP\Files\NotPermittedException
+ * @since 14.0.0
+ */
+ public function read() {
+ return $this->file->fopen('r');
+ }
+
+ /**
+ * Open the file as stream for writing, resulting resource can be operated as stream like the result from php's own fopen
+ *
+ * @return resource
+ * @throws \OCP\Files\NotPermittedException
+ * @since 14.0.0
+ */
+ public function write() {
+ return $this->file->fopen('w');
+ }
+
}
diff --git a/lib/public/Files/SimpleFS/ISimpleFile.php b/lib/public/Files/SimpleFS/ISimpleFile.php
index cd092056cda..a3cd3245cc7 100644
--- a/lib/public/Files/SimpleFS/ISimpleFile.php
+++ b/lib/public/Files/SimpleFS/ISimpleFile.php
@@ -99,4 +99,22 @@ interface ISimpleFile {
* @since 11.0.0
*/
public function getMimeType();
+
+ /**
+ * Open the file as stream for reading, resulting resource can be operated as stream like the result from php's own fopen
+ *
+ * @return resource
+ * @throws \OCP\Files\NotPermittedException
+ * @since 14.0.0
+ */
+ public function read();
+
+ /**
+ * Open the file as stream for writing, resulting resource can be operated as stream like the result from php's own fopen
+ *
+ * @return resource
+ * @throws \OCP\Files\NotPermittedException
+ * @since 14.0.0
+ */
+ public function write();
}
diff --git a/tests/lib/Files/SimpleFS/SimpleFileTest.php b/tests/lib/Files/SimpleFS/SimpleFileTest.php
index ab4970804a4..c1c53b15ecf 100644
--- a/tests/lib/Files/SimpleFS/SimpleFileTest.php
+++ b/tests/lib/Files/SimpleFS/SimpleFileTest.php
@@ -123,4 +123,20 @@ class SimpleFileTest extends \Test\TestCase {
$this->simpleFile->getContent();
}
+
+ public function testRead() {
+ $this->file->expects($this->once())
+ ->method('fopen')
+ ->with('r');
+
+ $this->simpleFile->read();
+ }
+
+ public function testWrite() {
+ $this->file->expects($this->once())
+ ->method('fopen')
+ ->with('w');
+
+ $this->simpleFile->write();
+ }
}