Merge pull request #10122 from nextcloud/feature/noid/appdata-fopen-stream

Add fopen method to ISimpleFile
This commit is contained in:
Morris Jobke 2018-07-11 13:40:09 +02:00 committed by GitHub
commit 229289d206
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 57 additions and 0 deletions

View file

@ -146,4 +146,27 @@ class SimpleFile implements ISimpleFile {
public function getMimeType() { public function getMimeType() {
return $this->file->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');
}
} }

View file

@ -99,4 +99,22 @@ interface ISimpleFile {
* @since 11.0.0 * @since 11.0.0
*/ */
public function getMimeType(); 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();
} }

View file

@ -123,4 +123,20 @@ class SimpleFileTest extends \Test\TestCase {
$this->simpleFile->getContent(); $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();
}
} }