summaryrefslogtreecommitdiffstats
path: root/apps/files_external/3rdparty/icewind/streams
diff options
context:
space:
mode:
Diffstat (limited to 'apps/files_external/3rdparty/icewind/streams')
-rw-r--r--apps/files_external/3rdparty/icewind/streams/.gitignore3
-rw-r--r--apps/files_external/3rdparty/icewind/streams/.travis.yml24
-rw-r--r--apps/files_external/3rdparty/icewind/streams/README.md7
-rw-r--r--apps/files_external/3rdparty/icewind/streams/composer.json29
-rw-r--r--apps/files_external/3rdparty/icewind/streams/src/CallbackWrapper.php46
-rw-r--r--apps/files_external/3rdparty/icewind/streams/src/CountWrapper.php15
-rw-r--r--apps/files_external/3rdparty/icewind/streams/src/Directory.php2
-rw-r--r--apps/files_external/3rdparty/icewind/streams/src/DirectoryFilter.php17
-rw-r--r--apps/files_external/3rdparty/icewind/streams/src/DirectoryWrapper.php49
-rw-r--r--apps/files_external/3rdparty/icewind/streams/src/File.php10
-rw-r--r--apps/files_external/3rdparty/icewind/streams/src/HashWrapper.php78
-rw-r--r--apps/files_external/3rdparty/icewind/streams/src/IteratorDirectory.php42
-rw-r--r--apps/files_external/3rdparty/icewind/streams/src/NullWrapper.php18
-rw-r--r--apps/files_external/3rdparty/icewind/streams/src/Path.php4
-rw-r--r--apps/files_external/3rdparty/icewind/streams/src/PathWrapper.php6
-rw-r--r--apps/files_external/3rdparty/icewind/streams/src/ReadHashWrapper.php40
-rw-r--r--apps/files_external/3rdparty/icewind/streams/src/RetryWrapper.php22
-rw-r--r--apps/files_external/3rdparty/icewind/streams/src/SeekableWrapper.php25
-rw-r--r--apps/files_external/3rdparty/icewind/streams/src/Url.php6
-rw-r--r--apps/files_external/3rdparty/icewind/streams/src/UrlCallback.php (renamed from apps/files_external/3rdparty/icewind/streams/src/UrlCallBack.php)60
-rw-r--r--apps/files_external/3rdparty/icewind/streams/src/Wrapper.php61
-rw-r--r--apps/files_external/3rdparty/icewind/streams/src/WrapperHandler.php114
-rw-r--r--apps/files_external/3rdparty/icewind/streams/src/WriteHashWrapper.php37
23 files changed, 423 insertions, 292 deletions
diff --git a/apps/files_external/3rdparty/icewind/streams/.gitignore b/apps/files_external/3rdparty/icewind/streams/.gitignore
index 4f389129e2d..a8fa5d4a955 100644
--- a/apps/files_external/3rdparty/icewind/streams/.gitignore
+++ b/apps/files_external/3rdparty/icewind/streams/.gitignore
@@ -1,3 +1,6 @@
.idea
vendor
composer.lock
+build
+example.php
+*.cache
diff --git a/apps/files_external/3rdparty/icewind/streams/.travis.yml b/apps/files_external/3rdparty/icewind/streams/.travis.yml
deleted file mode 100644
index 68efcd2c744..00000000000
--- a/apps/files_external/3rdparty/icewind/streams/.travis.yml
+++ /dev/null
@@ -1,24 +0,0 @@
-language: php
-php:
- - 5.4
- - 5.5
- - 5.6
- - 7.0
- - 7.1
- - 7.2
-
-env:
- global:
- - CURRENT_DIR=`pwd`
-
-install:
- - composer install --dev --no-interaction
-
-script:
- - mkdir -p build/logs
- - cd tests
- - phpunit --coverage-clover ../build/logs/clover.xml --configuration phpunit.xml
-
-after_script:
- - cd $CURRENT_DIR
- - php vendor/bin/coveralls -v
diff --git a/apps/files_external/3rdparty/icewind/streams/README.md b/apps/files_external/3rdparty/icewind/streams/README.md
index 88ab2dd92a3..0dbafc9df0b 100644
--- a/apps/files_external/3rdparty/icewind/streams/README.md
+++ b/apps/files_external/3rdparty/icewind/streams/README.md
@@ -1,8 +1,7 @@
# Streams #
-[![Build Status](https://travis-ci.org/icewind1991/Streams.svg?branch=master)](https://travis-ci.org/icewind1991/Streams)
-[![Coverage Status](https://img.shields.io/coveralls/icewind1991/Streams.svg)](https://coveralls.io/r/icewind1991/Streams?branch=master)
-[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/icewind1991/Streams/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/icewind1991/Streams/?branch=master)
+[![CI](https://github.com/icewind1991/Streams/actions/workflows/ci.yaml/badge.svg)](https://github.com/icewind1991/Streams/actions/workflows/ci.yaml)
+[![codecov](https://codecov.io/gh/icewind1991/Streams/branch/master/graph/badge.svg?token=bfPcAdGAaq)](https://codecov.io/gh/icewind1991/Streams)
Generic stream wrappers for php.
@@ -14,7 +13,7 @@ it wraps an existing stream and can thus be used for any stream in php
The callbacks are passed in the stream context along with the source stream
and can be any valid [php callable](http://php.net/manual/en/language.types.callable.php)
-###Example###
+### Example ###
```php
<?php
diff --git a/apps/files_external/3rdparty/icewind/streams/composer.json b/apps/files_external/3rdparty/icewind/streams/composer.json
index f2f3e0fc255..2a148158fbc 100644
--- a/apps/files_external/3rdparty/icewind/streams/composer.json
+++ b/apps/files_external/3rdparty/icewind/streams/composer.json
@@ -1,24 +1,29 @@
{
- "name" : "icewind/streams",
- "description" : "A set of generic stream wrappers",
- "license" : "MIT",
- "authors" : [
+ "name": "icewind/streams",
+ "description": "A set of generic stream wrappers",
+ "license": "MIT",
+ "authors": [
{
- "name" : "Robin Appelman",
+ "name": "Robin Appelman",
"email": "icewind@owncloud.com"
}
],
- "require" : {
- "php": ">=5.3"
+ "require": {
+ "php": ">=7.1"
},
- "require-dev" : {
- "satooshi/php-coveralls": "v1.0.0",
- "phpunit/phpunit": "^4.8"
+ "require-dev": {
+ "phpunit/phpunit": "^9",
+ "friendsofphp/php-cs-fixer": "^2",
+ "phpstan/phpstan": "^0.12"
},
- "autoload" : {
+ "autoload": {
"psr-4": {
- "Icewind\\Streams\\Tests\\": "tests/",
"Icewind\\Streams\\": "src/"
}
+ },
+ "autoload-dev": {
+ "psr-4": {
+ "Icewind\\Streams\\Tests\\": "tests/"
+ }
}
}
diff --git a/apps/files_external/3rdparty/icewind/streams/src/CallbackWrapper.php b/apps/files_external/3rdparty/icewind/streams/src/CallbackWrapper.php
index 67f9110d100..5d78b5a3db0 100644
--- a/apps/files_external/3rdparty/icewind/streams/src/CallbackWrapper.php
+++ b/apps/files_external/3rdparty/icewind/streams/src/CallbackWrapper.php
@@ -25,27 +25,27 @@ namespace Icewind\Streams;
*/
class CallbackWrapper extends Wrapper {
/**
- * @var callable
+ * @var callable|null
*/
protected $readCallback;
/**
- * @var callable
+ * @var callable|null
*/
protected $writeCallback;
/**
- * @var callable
+ * @var callable|null
*/
protected $closeCallback;
/**
- * @var callable
+ * @var callable|null
*/
protected $readDirCallBack;
/**
- * @var callable
+ * @var callable|null
*/
protected $preCloseCallback;
@@ -53,30 +53,28 @@ class CallbackWrapper extends Wrapper {
* Wraps a stream with the provided callbacks
*
* @param resource $source
- * @param callable $read (optional)
- * @param callable $write (optional)
- * @param callable $close (optional)
- * @param callable $readDir (optional)
- * @return resource
+ * @param callable|null $read (optional)
+ * @param callable|null $write (optional)
+ * @param callable|null $close (optional)
+ * @param callable|null $readDir (optional)
+ * @param callable|null $preClose (optional)
+ * @return resource|bool
*
- * @throws \BadMethodCallException
*/
public static function wrap($source, $read = null, $write = null, $close = null, $readDir = null, $preClose = null) {
- $context = stream_context_create(array(
- 'callback' => array(
- 'source' => $source,
- 'read' => $read,
- 'write' => $write,
- 'close' => $close,
- 'readDir' => $readDir,
- 'preClose' => $preClose,
- )
- ));
- return Wrapper::wrapSource($source, $context, 'callback', '\Icewind\Streams\CallbackWrapper');
+ $context = [
+ 'source' => $source,
+ 'read' => $read,
+ 'write' => $write,
+ 'close' => $close,
+ 'readDir' => $readDir,
+ 'preClose' => $preClose,
+ ];
+ return self::wrapSource($source, $context);
}
protected function open() {
- $context = $this->loadContext('callback');
+ $context = $this->loadContext();
$this->readCallback = $context['read'];
$this->writeCallback = $context['write'];
@@ -112,7 +110,7 @@ class CallbackWrapper extends Wrapper {
public function stream_close() {
if (is_callable($this->preCloseCallback)) {
- call_user_func($this->preCloseCallback, $this->loadContext('callback')['source']);
+ call_user_func($this->preCloseCallback, $this->source);
// prevent further calls by potential PHP 7 GC ghosts
$this->preCloseCallback = null;
}
diff --git a/apps/files_external/3rdparty/icewind/streams/src/CountWrapper.php b/apps/files_external/3rdparty/icewind/streams/src/CountWrapper.php
index 8b86ab9187c..b3346209aed 100644
--- a/apps/files_external/3rdparty/icewind/streams/src/CountWrapper.php
+++ b/apps/files_external/3rdparty/icewind/streams/src/CountWrapper.php
@@ -55,7 +55,7 @@ class CountWrapper extends Wrapper {
*
* @param resource $source
* @param callable $callback
- * @return resource
+ * @return resource|bool
*
* @throws \BadMethodCallException
*/
@@ -63,17 +63,14 @@ class CountWrapper extends Wrapper {
if (!is_callable($callback)) {
throw new \InvalidArgumentException('Invalid or missing callback');
}
- $context = stream_context_create(array(
- 'count' => array(
- 'source' => $source,
- 'callback' => $callback
- )
- ));
- return Wrapper::wrapSource($source, $context, 'callback', '\Icewind\Streams\CountWrapper');
+ return self::wrapSource($source, [
+ 'source' => $source,
+ 'callback' => $callback
+ ]);
}
protected function open() {
- $context = $this->loadContext('count');
+ $context = $this->loadContext();
$this->callback = $context['callback'];
return true;
}
diff --git a/apps/files_external/3rdparty/icewind/streams/src/Directory.php b/apps/files_external/3rdparty/icewind/streams/src/Directory.php
index c80a878386b..912be76acfa 100644
--- a/apps/files_external/3rdparty/icewind/streams/src/Directory.php
+++ b/apps/files_external/3rdparty/icewind/streams/src/Directory.php
@@ -19,7 +19,7 @@ interface Directory {
public function dir_opendir($path, $options);
/**
- * @return string
+ * @return string|bool
*/
public function dir_readdir();
diff --git a/apps/files_external/3rdparty/icewind/streams/src/DirectoryFilter.php b/apps/files_external/3rdparty/icewind/streams/src/DirectoryFilter.php
index 4b869699000..80b27e8bab8 100644
--- a/apps/files_external/3rdparty/icewind/streams/src/DirectoryFilter.php
+++ b/apps/files_external/3rdparty/icewind/streams/src/DirectoryFilter.php
@@ -25,7 +25,7 @@ class DirectoryFilter extends DirectoryWrapper {
* @return bool
*/
public function dir_opendir($path, $options) {
- $context = $this->loadContext('filter');
+ $context = $this->loadContext();
$this->filter = $context['filter'];
return true;
}
@@ -36,7 +36,7 @@ class DirectoryFilter extends DirectoryWrapper {
public function dir_readdir() {
$file = readdir($this->source);
$filter = $this->filter;
- // keep reading untill we have an accepted entry or we're at the end of the folder
+ // keep reading until we have an accepted entry or we're at the end of the folder
while ($file !== false && $filter($file) === false) {
$file = readdir($this->source);
}
@@ -46,15 +46,12 @@ class DirectoryFilter extends DirectoryWrapper {
/**
* @param resource $source
* @param callable $filter
- * @return resource
+ * @return resource|bool
*/
public static function wrap($source, callable $filter) {
- $options = array(
- 'filter' => array(
- 'source' => $source,
- 'filter' => $filter
- )
- );
- return self::wrapWithOptions($options, '\Icewind\Streams\DirectoryFilter');
+ return self::wrapSource($source, [
+ 'source' => $source,
+ 'filter' => $filter
+ ]);
}
}
diff --git a/apps/files_external/3rdparty/icewind/streams/src/DirectoryWrapper.php b/apps/files_external/3rdparty/icewind/streams/src/DirectoryWrapper.php
index 63e4805a807..7f2f5c291c6 100644
--- a/apps/files_external/3rdparty/icewind/streams/src/DirectoryWrapper.php
+++ b/apps/files_external/3rdparty/icewind/streams/src/DirectoryWrapper.php
@@ -7,37 +7,9 @@
namespace Icewind\Streams;
-class DirectoryWrapper implements Directory {
- /**
- * @var resource
- */
- public $context;
-
- /**
- * @var resource
- */
- protected $source;
-
- /**
- * Load the source from the stream context and return the context options
- *
- * @param string $name
- * @return array
- * @throws \Exception
- */
- protected function loadContext($name) {
- $context = stream_context_get_options($this->context);
- if (isset($context[$name])) {
- $context = $context[$name];
- } else {
- throw new \BadMethodCallException('Invalid context, "' . $name . '" options not set');
- }
- if (isset($context['source']) and is_resource($context['source'])) {
- $this->source = $context['source'];
- } else {
- throw new \BadMethodCallException('Invalid context, source not set');
- }
- return $context;
+class DirectoryWrapper extends Wrapper implements Directory {
+ public function stream_open($path, $mode, $options, &$opened_path) {
+ return false;
}
/**
@@ -46,7 +18,7 @@ class DirectoryWrapper implements Directory {
* @return bool
*/
public function dir_opendir($path, $options) {
- $this->loadContext('dir');
+ $this->loadContext();
return true;
}
@@ -72,17 +44,4 @@ class DirectoryWrapper implements Directory {
rewinddir($this->source);
return true;
}
-
- /**
- * @param array $options the options for the context to wrap the stream with
- * @param string $class
- * @return resource
- */
- protected static function wrapWithOptions($options, $class) {
- $context = stream_context_create($options);
- stream_wrapper_register('dirwrapper', $class);
- $wrapped = opendir('dirwrapper://', $context);
- stream_wrapper_unregister('dirwrapper');
- return $wrapped;
- }
}
diff --git a/apps/files_external/3rdparty/icewind/streams/src/File.php b/apps/files_external/3rdparty/icewind/streams/src/File.php
index 252b7b8971f..9662414a79e 100644
--- a/apps/files_external/3rdparty/icewind/streams/src/File.php
+++ b/apps/files_external/3rdparty/icewind/streams/src/File.php
@@ -15,7 +15,7 @@ interface File {
* @param string $path
* @param string $mode
* @param int $options
- * @param string &$opened_path
+ * @param string $opened_path
* @return bool
*/
public function stream_open($path, $mode, $options, &$opened_path);
@@ -28,19 +28,19 @@ interface File {
public function stream_seek($offset, $whence = SEEK_SET);
/**
- * @return int
+ * @return int|false
*/
public function stream_tell();
/**
* @param int $count
- * @return string
+ * @return string|false
*/
public function stream_read($count);
/**
* @param string $data
- * @return int
+ * @return int|false
*/
public function stream_write($data);
@@ -59,7 +59,7 @@ interface File {
public function stream_truncate($size);
/**
- * @return array
+ * @return array|false
*/
public function stream_stat();
diff --git a/apps/files_external/3rdparty/icewind/streams/src/HashWrapper.php b/apps/files_external/3rdparty/icewind/streams/src/HashWrapper.php
new file mode 100644
index 00000000000..616c2fe506f
--- /dev/null
+++ b/apps/files_external/3rdparty/icewind/streams/src/HashWrapper.php
@@ -0,0 +1,78 @@
+<?php
+/**
+ * @copyright Copyright (c) 2019, Roeland Jago Douma <roeland@famdouma.nl>
+ *
+ * @author Roeland Jago Douma <roeland@famdouma.nl>
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+namespace Icewind\Streams;
+
+abstract class HashWrapper extends Wrapper {
+
+ /**
+ * @var callable|null
+ */
+ private $callback;
+
+ /**
+ * @var resource|\HashContext
+ */
+ private $hashContext;
+
+ /**
+ * Wraps a stream to make it seekable
+ *
+ * @param resource $source
+ * @param string $hash
+ * @param callable $callback
+ * @return resource|bool
+ *
+ * @throws \BadMethodCallException
+ */
+ public static function wrap($source, $hash, $callback) {
+ $context = [
+ 'hash' => $hash,
+ 'callback' => $callback,
+ ];
+ return self::wrapSource($source, $context);
+ }
+
+ public function dir_opendir($path, $options) {
+ return false;
+ }
+
+ public function stream_open($path, $mode, $options, &$opened_path) {
+ $context = $this->loadContext();
+ $this->callback = $context['callback'];
+ $this->hashContext = hash_init($context['hash']);
+ return true;
+ }
+
+ protected function updateHash($data) {
+ hash_update($this->hashContext, $data);
+ }
+
+ public function stream_close() {
+ $hash = hash_final($this->hashContext);
+ if ($this->hashContext !== false && is_callable($this->callback)) {
+ call_user_func($this->callback, $hash);
+ }
+ return parent::stream_close();
+ }
+}
diff --git a/apps/files_external/3rdparty/icewind/streams/src/IteratorDirectory.php b/apps/files_external/3rdparty/icewind/streams/src/IteratorDirectory.php
index 6dfa42a8b68..a3872ddf474 100644
--- a/apps/files_external/3rdparty/icewind/streams/src/IteratorDirectory.php
+++ b/apps/files_external/3rdparty/icewind/streams/src/IteratorDirectory.php
@@ -20,7 +20,7 @@ namespace Icewind\Streams;
*
* Either 'array' or 'iterator' need to be set, if both are set, 'iterator' takes preference
*/
-class IteratorDirectory implements Directory {
+class IteratorDirectory extends WrapperHandler implements Directory {
/**
* @var resource
*/
@@ -36,18 +36,13 @@ class IteratorDirectory implements Directory {
*
* @param string $name
* @return array
- * @throws \Exception
+ * @throws \BadMethodCallException
*/
- protected function loadContext($name) {
- $context = stream_context_get_options($this->context);
- if (isset($context[$name])) {
- $context = $context[$name];
- } else {
- throw new \BadMethodCallException('Invalid context, "' . $name . '" options not set');
- }
+ protected function loadContext($name = null) {
+ $context = parent::loadContext($name);
if (isset($context['iterator'])) {
$this->iterator = $context['iterator'];
- } else if (isset($context['array'])) {
+ } elseif (isset($context['array'])) {
$this->iterator = new \ArrayIterator($context['array']);
} else {
throw new \BadMethodCallException('Invalid context, iterator or array not set');
@@ -61,12 +56,12 @@ class IteratorDirectory implements Directory {
* @return bool
*/
public function dir_opendir($path, $options) {
- $this->loadContext('dir');
+ $this->loadContext();
return true;
}
/**
- * @return string
+ * @return string|bool
*/
public function dir_readdir() {
if ($this->iterator->valid()) {
@@ -97,27 +92,22 @@ class IteratorDirectory implements Directory {
* Creates a directory handle from the provided array or iterator
*
* @param \Iterator | array $source
- * @return resource
+ * @return resource|bool
*
* @throws \BadMethodCallException
*/
public static function wrap($source) {
if ($source instanceof \Iterator) {
- $context = stream_context_create(array(
- 'dir' => array(
- 'iterator' => $source)
- ));
- } else if (is_array($source)) {
- $context = stream_context_create(array(
- 'dir' => array(
- 'array' => $source)
- ));
+ $options = [
+ 'iterator' => $source
+ ];
+ } elseif (is_array($source)) {
+ $options = [
+ 'array' => $source
+ ];
} else {
throw new \BadMethodCallException('$source should be an Iterator or array');
}
- stream_wrapper_register('iterator', '\Icewind\Streams\IteratorDirectory');
- $wrapped = opendir('iterator://', $context);
- stream_wrapper_unregister('iterator');
- return $wrapped;
+ return self::wrapSource(self::NO_SOURCE_DIR, $options);
}
}
diff --git a/apps/files_external/3rdparty/icewind/streams/src/NullWrapper.php b/apps/files_external/3rdparty/icewind/streams/src/NullWrapper.php
index b6c71d98fc4..92aef2c7a2d 100644
--- a/apps/files_external/3rdparty/icewind/streams/src/NullWrapper.php
+++ b/apps/files_external/3rdparty/icewind/streams/src/NullWrapper.php
@@ -11,29 +11,17 @@ namespace Icewind\Streams;
* Stream wrapper that does nothing, used for tests
*/
class NullWrapper extends Wrapper {
- /**
- * Wraps a stream with the provided callbacks
- *
- * @param resource $source
- * @return resource
- *
- * @throws \BadMethodCallException
- */
public static function wrap($source) {
- $context = stream_context_create(array(
- 'null' => array(
- 'source' => $source)
- ));
- return Wrapper::wrapSource($source, $context, 'null', '\Icewind\Streams\NullWrapper');
+ return self::wrapSource($source);
}
public function stream_open($path, $mode, $options, &$opened_path) {
- $this->loadContext('null');
+ $this->loadContext();
return true;
}
public function dir_opendir($path, $options) {
- $this->loadContext('null');
+ $this->loadContext();
return true;
}
}
diff --git a/apps/files_external/3rdparty/icewind/streams/src/Path.php b/apps/files_external/3rdparty/icewind/streams/src/Path.php
index bef9fd5f616..42d74a2ac1a 100644
--- a/apps/files_external/3rdparty/icewind/streams/src/Path.php
+++ b/apps/files_external/3rdparty/icewind/streams/src/Path.php
@@ -38,7 +38,7 @@ class Path {
* @param string $class
* @param array $contextOptions
*/
- public function __construct($class, $contextOptions = array()) {
+ public function __construct($class, $contextOptions = []) {
$this->class = $class;
$this->contextOptions = $contextOptions;
}
@@ -75,7 +75,7 @@ class Path {
*/
protected function appendDefaultContent($values) {
if (!is_array(current($values))) {
- $values = array($this->getProtocol() => $values);
+ $values = [$this->getProtocol() => $values];
}
$context = stream_context_get_default();
$defaults = stream_context_get_options($context);
diff --git a/apps/files_external/3rdparty/icewind/streams/src/PathWrapper.php b/apps/files_external/3rdparty/icewind/streams/src/PathWrapper.php
index 88af7e17b33..d9f3014c381 100644
--- a/apps/files_external/3rdparty/icewind/streams/src/PathWrapper.php
+++ b/apps/files_external/3rdparty/icewind/streams/src/PathWrapper.php
@@ -16,10 +16,8 @@ class PathWrapper extends NullWrapper {
* @return Path|string
*/
public static function getPath($source) {
- return new Path(__CLASS__, [
- 'null' => [
- 'source' => $source
- ]
+ return new Path(NullWrapper::class, [
+ NullWrapper::getProtocol() => ['source' => $source]
]);
}
}
diff --git a/apps/files_external/3rdparty/icewind/streams/src/ReadHashWrapper.php b/apps/files_external/3rdparty/icewind/streams/src/ReadHashWrapper.php
new file mode 100644
index 00000000000..16cf006ccf5
--- /dev/null
+++ b/apps/files_external/3rdparty/icewind/streams/src/ReadHashWrapper.php
@@ -0,0 +1,40 @@
+<?php
+/**
+ * @copyright Copyright (c) 2019, Roeland Jago Douma <roeland@famdouma.nl>
+ *
+ * @author Roeland Jago Douma <roeland@famdouma.nl>
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+namespace Icewind\Streams;
+
+/**
+ * Wrapper that calculates the hash on the stream on read
+ *
+ * The stream and hash should be passed in when wrapping the stream.
+ * On close the callback will be called with the calculated checksum.
+ *
+ * For supported hashes see: http://php.net/manual/en/function.hash-algos.php
+ */
+class ReadHashWrapper extends HashWrapper {
+ public function stream_read($count) {
+ $data = parent::stream_read($count);
+ $this->updateHash($data);
+ return $data;
+ }
+}
diff --git a/apps/files_external/3rdparty/icewind/streams/src/RetryWrapper.php b/apps/files_external/3rdparty/icewind/streams/src/RetryWrapper.php
index 8238f19f7c9..d4727aa96cd 100644
--- a/apps/files_external/3rdparty/icewind/streams/src/RetryWrapper.php
+++ b/apps/files_external/3rdparty/icewind/streams/src/RetryWrapper.php
@@ -11,25 +11,8 @@ namespace Icewind\Streams;
* Wrapper that retries reads/writes to remote streams that dont deliver/recieve all requested data at once
*/
class RetryWrapper extends Wrapper {
-
- /**
- * Wraps a stream with the provided callbacks
- *
- * @param resource $source
- * @return resource
- */
public static function wrap($source) {
- $context = stream_context_create(array(
- 'retry' => array(
- 'source' => $source
- )
- ));
- return Wrapper::wrapSource($source, $context, 'retry', '\Icewind\Streams\RetryWrapper');
- }
-
- protected function open() {
- $this->loadContext('retry');
- return true;
+ return self::wrapSource($source);
}
public function dir_opendir($path, $options) {
@@ -37,7 +20,8 @@ class RetryWrapper extends Wrapper {
}
public function stream_open($path, $mode, $options, &$opened_path) {
- return $this->open();
+ $this->loadContext();
+ return true;
}
public function stream_read($count) {
diff --git a/apps/files_external/3rdparty/icewind/streams/src/SeekableWrapper.php b/apps/files_external/3rdparty/icewind/streams/src/SeekableWrapper.php
index d41fd73ec9c..f131e75308e 100644
--- a/apps/files_external/3rdparty/icewind/streams/src/SeekableWrapper.php
+++ b/apps/files_external/3rdparty/icewind/streams/src/SeekableWrapper.php
@@ -25,21 +25,8 @@ class SeekableWrapper extends Wrapper {
*/
protected $cache;
- /**
- * Wraps a stream to make it seekable
- *
- * @param resource $source
- * @return resource
- *
- * @throws \BadMethodCallException
- */
public static function wrap($source) {
- $context = stream_context_create(array(
- 'callback' => array(
- 'source' => $source
- )
- ));
- return Wrapper::wrapSource($source, $context, 'callback', '\Icewind\Streams\SeekableWrapper');
+ return self::wrapSource($source);
}
public function dir_opendir($path, $options) {
@@ -47,8 +34,12 @@ class SeekableWrapper extends Wrapper {
}
public function stream_open($path, $mode, $options, &$opened_path) {
- $this->loadContext('callback');
- $this->cache = fopen('php://temp', 'w+');
+ $this->loadContext();
+ $cache = fopen('php://temp', 'w+');
+ if ($cache === false) {
+ return false;
+ }
+ $this->cache = $cache;
return true;
}
@@ -72,7 +63,7 @@ class SeekableWrapper extends Wrapper {
public function stream_seek($offset, $whence = SEEK_SET) {
if ($whence === SEEK_SET) {
$target = $offset;
- } else if ($whence === SEEK_CUR) {
+ } elseif ($whence === SEEK_CUR) {
$current = ftell($this->cache);
$target = $current + $offset;
} else {
diff --git a/apps/files_external/3rdparty/icewind/streams/src/Url.php b/apps/files_external/3rdparty/icewind/streams/src/Url.php
index d6822608a33..38cbbdd89b2 100644
--- a/apps/files_external/3rdparty/icewind/streams/src/Url.php
+++ b/apps/files_external/3rdparty/icewind/streams/src/Url.php
@@ -22,7 +22,7 @@ interface Url {
* @param string $path
* @param string $mode
* @param int $options
- * @param string &$opened_path
+ * @param string $opened_path
* @return bool
*/
public function stream_open($path, $mode, $options, &$opened_path);
@@ -50,7 +50,7 @@ interface Url {
public function rmdir($path, $options);
/**
- * @param string
+ * @param string $path
* @return bool
*/
public function unlink($path);
@@ -58,7 +58,7 @@ interface Url {
/**
* @param string $path
* @param int $flags
- * @return array
+ * @return array|false
*/
public function url_stat($path, $flags);
}
diff --git a/apps/files_external/3rdparty/icewind/streams/src/UrlCallBack.php b/apps/files_external/3rdparty/icewind/streams/src/UrlCallback.php
index 580bfc6ba22..09ba2aefee6 100644
--- a/apps/files_external/3rdparty/icewind/streams/src/UrlCallBack.php
+++ b/apps/files_external/3rdparty/icewind/streams/src/UrlCallback.php
@@ -47,24 +47,30 @@ class UrlCallback extends Wrapper implements Url {
* @return \Icewind\Streams\Path
*
* @throws \BadMethodCallException
- * @throws \Exception
*/
- public static function wrap($source, $fopen = null, $opendir = null, $mkdir = null, $rename = null, $rmdir = null,
- $unlink = null, $stat = null) {
- $options = array(
- 'source' => $source,
- 'fopen' => $fopen,
+ public static function wrap(
+ $source,
+ $fopen = null,
+ $opendir = null,
+ $mkdir = null,
+ $rename = null,
+ $rmdir = null,
+ $unlink = null,
+ $stat = null
+ ) {
+ return new Path(static::class, [
+ 'source' => $source,
+ 'fopen' => $fopen,
'opendir' => $opendir,
- 'mkdir' => $mkdir,
- 'rename' => $rename,
- 'rmdir' => $rmdir,
- 'unlink' => $unlink,
- 'stat' => $stat
- );
- return new Path('\Icewind\Streams\UrlCallBack', $options);
+ 'mkdir' => $mkdir,
+ 'rename' => $rename,
+ 'rmdir' => $rmdir,
+ 'unlink' => $unlink,
+ 'stat' => $stat
+ ]);
}
- protected function loadContext($url) {
+ protected function loadUrlContext($url) {
list($protocol) = explode('://', $url);
$options = stream_context_get_options($this->context);
return $options[$protocol];
@@ -77,40 +83,48 @@ class UrlCallback extends Wrapper implements Url {
}
public function stream_open($path, $mode, $options, &$opened_path) {
- $context = $this->loadContext($path);
+ $context = $this->loadUrlContext($path);
$this->callCallBack($context, 'fopen');
- $this->setSourceStream(fopen($context['source'], $mode));
+ $source = fopen($context['source'], $mode);
+ if ($source === false) {
+ return false;
+ }
+ $this->setSourceStream($source);
return true;
}
public function dir_opendir($path, $options) {
- $context = $this->loadContext($path);
+ $context = $this->loadUrlContext($path);
$this->callCallBack($context, 'opendir');
- $this->setSourceStream(opendir($context['source']));
+ $source = opendir($context['source']);
+ if ($source === false) {
+ return false;
+ }
+ $this->setSourceStream($source);
return true;
}
public function mkdir($path, $mode, $options) {
- $context = $this->loadContext($path);
+ $context = $this->loadUrlContext($path);
$this->callCallBack($context, 'mkdir');
- return mkdir($context['source'], $mode, $options & STREAM_MKDIR_RECURSIVE);
+ return mkdir($context['source'], $mode, ($options & STREAM_MKDIR_RECURSIVE) > 0);
}
public function rmdir($path, $options) {
- $context = $this->loadContext($path);
+ $context = $this->loadUrlContext($path);
$this->callCallBack($context, 'rmdir');
return rmdir($context['source']);
}
public function rename($source, $target) {
- $context = $this->loadContext($source);
+ $context = $this->loadUrlContext($source);
$this->callCallBack($context, 'rename');
list(, $target) = explode('://', $target);
return rename($context['source'], $target);
}
public function unlink($path) {
- $context = $this->loadContext($path);
+ $context = $this->loadUrlContext($path);
$this->callCallBack($context, 'unlink');
return unlink($context['source']);
}
diff --git a/apps/files_external/3rdparty/icewind/streams/src/Wrapper.php b/apps/files_external/3rdparty/icewind/streams/src/Wrapper.php
index babd2c1a0b3..5dc8b29e774 100644
--- a/apps/files_external/3rdparty/icewind/streams/src/Wrapper.php
+++ b/apps/files_external/3rdparty/icewind/streams/src/Wrapper.php
@@ -12,7 +12,7 @@ namespace Icewind\Streams;
*
* This wrapper itself doesn't implement any functionality but is just a base class for other wrappers to extend
*/
-abstract class Wrapper implements File, Directory {
+abstract class Wrapper extends WrapperHandler implements File, Directory {
/**
* @var resource
*/
@@ -25,44 +25,15 @@ abstract class Wrapper implements File, Directory {
*/
protected $source;
- protected static function wrapSource($source, $context, $protocol, $class) {
- if (!is_resource($source)) {
- throw new \BadMethodCallException();
- }
- try {
- stream_wrapper_register($protocol, $class);
- if (self::isDirectoryHandle($source)) {
- $wrapped = opendir($protocol . '://', $context);
- } else {
- $wrapped = fopen($protocol . '://', 'r+', false, $context);
- }
- } catch (\BadMethodCallException $e) {
- stream_wrapper_unregister($protocol);
- throw $e;
- }
- stream_wrapper_unregister($protocol);
- return $wrapped;
- }
-
- protected static function isDirectoryHandle($resource) {
- $meta = stream_get_meta_data($resource);
- return $meta['stream_type'] == 'dir';
- }
-
/**
- * Load the source from the stream context and return the context options
- *
- * @param string $name
- * @return array
- * @throws \Exception
+ * @param resource $source
*/
- protected function loadContext($name) {
- $context = stream_context_get_options($this->context);
- if (isset($context[$name])) {
- $context = $context[$name];
- } else {
- throw new \BadMethodCallException('Invalid context, "' . $name . '" options not set');
- }
+ protected function setSourceStream($source) {
+ $this->source = $source;
+ }
+
+ protected function loadContext($name = null) {
+ $context = parent::loadContext($name);
if (isset($context['source']) and is_resource($context['source'])) {
$this->setSourceStream($context['source']);
} else {
@@ -71,13 +42,6 @@ abstract class Wrapper implements File, Directory {
return $context;
}
- /**
- * @param resource $source
- */
- protected function setSourceStream($source) {
- $this->source = $source;
- }
-
public function stream_seek($offset, $whence = SEEK_SET) {
$result = fseek($this->source, $offset, $whence);
return $result == 0 ? true : false;
@@ -98,14 +62,13 @@ abstract class Wrapper implements File, Directory {
public function stream_set_option($option, $arg1, $arg2) {
switch ($option) {
case STREAM_OPTION_BLOCKING:
- stream_set_blocking($this->source, $arg1);
- break;
+ return stream_set_blocking($this->source, (bool)$arg1);
case STREAM_OPTION_READ_TIMEOUT:
- stream_set_timeout($this->source, $arg1, $arg2);
- break;
+ return stream_set_timeout($this->source, $arg1, $arg2);
case STREAM_OPTION_WRITE_BUFFER:
- stream_set_write_buffer($this->source, $arg1);
+ return stream_set_write_buffer($this->source, $arg1) === 0;
}
+ return false;
}
public function stream_truncate($size) {
diff --git a/apps/files_external/3rdparty/icewind/streams/src/WrapperHandler.php b/apps/files_external/3rdparty/icewind/streams/src/WrapperHandler.php
new file mode 100644
index 00000000000..52a02feb19f
--- /dev/null
+++ b/apps/files_external/3rdparty/icewind/streams/src/WrapperHandler.php
@@ -0,0 +1,114 @@
+<?php
+/**
+ * @copyright Copyright (c) 2019 Robin Appelman <robin@icewind.nl>
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+namespace Icewind\Streams;
+
+class WrapperHandler {
+ /** @var resource $context */
+ protected $context;
+
+ const NO_SOURCE_DIR = 1;
+
+ /**
+ * get the protocol name that is generated for the class
+ * @param string|null $class
+ * @return string
+ */
+ public static function getProtocol($class = null) {
+ if ($class === null) {
+ $class = static::class;
+ }
+
+ $parts = explode('\\', $class);
+ return strtolower(array_pop($parts));
+ }
+
+ private static function buildContext($protocol, $context, $source) {
+ if (is_array($context)) {
+ $context['source'] = $source;
+ return stream_context_create([$protocol => $context]);
+ } else {
+ return $context;
+ }
+ }
+
+ /**
+ * @param resource|int $source
+ * @param resource|array $context
+ * @param string|null $protocol deprecated, protocol is now automatically generated
+ * @param string|null $class deprecated, class is now automatically generated
+ * @return bool|resource
+ */
+ protected static function wrapSource($source, $context = [], $protocol = null, $class = null) {
+ if ($class === null) {
+ $class = static::class;
+ }
+
+ if ($protocol === null) {
+ $protocol = self::getProtocol($class);
+ }
+
+ $context = self::buildContext($protocol, $context, $source);
+ try {
+ stream_wrapper_register($protocol, $class);
+ if (self::isDirectoryHandle($source)) {
+ return opendir($protocol . '://', $context);
+ } else {
+ return fopen($protocol . '://', 'r+', false, $context);
+ }
+ } finally {
+ stream_wrapper_unregister($protocol);
+ }
+ }
+
+ protected static function isDirectoryHandle($resource) {
+ if ($resource === self::NO_SOURCE_DIR) {
+ return true;
+ }
+ if (!is_resource($resource)) {
+ throw new \BadMethodCallException('Invalid stream source');
+ }
+ $meta = stream_get_meta_data($resource);
+ return $meta['stream_type'] === 'dir' || $meta['stream_type'] === 'user-space-dir';
+ }
+
+ /**
+ * Load the source from the stream context and return the context options
+ *
+ * @param string|null $name if not set, the generated protocol name is used
+ * @return array
+ * @throws \BadMethodCallException
+ */
+ protected function loadContext($name = null) {
+ if ($name === null) {
+ $parts = explode('\\', static::class);
+ $name = strtolower(array_pop($parts));
+ }
+
+ $context = stream_context_get_options($this->context);
+ if (isset($context[$name])) {
+ $context = $context[$name];
+ } else {
+ throw new \BadMethodCallException('Invalid context, "' . $name . '" options not set');
+ }
+ return $context;
+ }
+}
diff --git a/apps/files_external/3rdparty/icewind/streams/src/WriteHashWrapper.php b/apps/files_external/3rdparty/icewind/streams/src/WriteHashWrapper.php
new file mode 100644
index 00000000000..279d9fd10e3
--- /dev/null
+++ b/apps/files_external/3rdparty/icewind/streams/src/WriteHashWrapper.php
@@ -0,0 +1,37 @@
+<?php
+/**
+ * @copyright Copyright (c) 2019 Robin Appelman <robin@icewind.nl>
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+namespace Icewind\Streams;
+
+/**
+ * Wrapper that calculates the hash on the stream on write
+ *
+ * The stream and hash should be passed in when wrapping the stream.
+ * On close the callback will be called with the calculated checksum.
+ *
+ * For supported hashes see: http://php.net/manual/en/function.hash-algos.php
+ */
+class WriteHashWrapper extends HashWrapper {
+ public function stream_write($data) {
+ $this->updateHash($data);
+ return parent::stream_write($data);
+ }
+}