Skip to content

Commit 4c0ce64

Browse files
authored
Merge pull request #244 from nextcloud/backport/stable15/streams-0.7.1
Backport/stable15/streams 0.7.1
2 parents 4c31d75 + a67e6c0 commit 4c0ce64

File tree

4 files changed

+28
-16
lines changed

4 files changed

+28
-16
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
"doctrine/dbal": "dev-2.5-pg10",
2525
"guzzlehttp/guzzle": "6.3.3",
2626
"icewind/searchdav": "1.0.1",
27-
"icewind/Streams": "0.6.1",
27+
"icewind/Streams": "v0.7.1",
2828
"interfasys/lognormalizer": "^v1.0",
2929
"jeremeamia/superclosure": "2.1.0",
3030
"leafo/scssphp": "0.7.7",

composer.lock

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

composer/installed.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1116,17 +1116,17 @@
11161116
},
11171117
{
11181118
"name": "icewind/streams",
1119-
"version": "0.6.1",
1120-
"version_normalized": "0.6.1.0",
1119+
"version": "v0.7.1",
1120+
"version_normalized": "0.7.1.0",
11211121
"source": {
11221122
"type": "git",
11231123
"url": "https://github.com/icewind1991/Streams.git",
1124-
"reference": "0a78597117d8a02937ea05206f219294449fb06e"
1124+
"reference": "4db3ed6c366e90b958d00e1d4c6360a9b39b2121"
11251125
},
11261126
"dist": {
11271127
"type": "zip",
1128-
"url": "https://api.github.com/repos/icewind1991/Streams/zipball/0a78597117d8a02937ea05206f219294449fb06e",
1129-
"reference": "0a78597117d8a02937ea05206f219294449fb06e",
1128+
"url": "https://api.github.com/repos/icewind1991/Streams/zipball/4db3ed6c366e90b958d00e1d4c6360a9b39b2121",
1129+
"reference": "4db3ed6c366e90b958d00e1d4c6360a9b39b2121",
11301130
"shasum": ""
11311131
},
11321132
"require": {
@@ -1136,7 +1136,7 @@
11361136
"phpunit/phpunit": "^4.8",
11371137
"satooshi/php-coveralls": "v1.0.0"
11381138
},
1139-
"time": "2018-04-24T09:07:38+00:00",
1139+
"time": "2019-02-15T12:57:29+00:00",
11401140
"type": "library",
11411141
"installation-source": "dist",
11421142
"autoload": {

icewind/streams/src/CallbackWrapper.php

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,11 @@ class CallbackWrapper extends Wrapper {
4444
*/
4545
protected $readDirCallBack;
4646

47+
/**
48+
* @var callable
49+
*/
50+
protected $preCloseCallback;
51+
4752
/**
4853
* Wraps a stream with the provided callbacks
4954
*
@@ -56,14 +61,15 @@ class CallbackWrapper extends Wrapper {
5661
*
5762
* @throws \BadMethodCallException
5863
*/
59-
public static function wrap($source, $read = null, $write = null, $close = null, $readDir = null) {
64+
public static function wrap($source, $read = null, $write = null, $close = null, $readDir = null, $preClose = null) {
6065
$context = stream_context_create(array(
6166
'callback' => array(
6267
'source' => $source,
6368
'read' => $read,
6469
'write' => $write,
6570
'close' => $close,
66-
'readDir' => $readDir
71+
'readDir' => $readDir,
72+
'preClose' => $preClose,
6773
)
6874
));
6975
return Wrapper::wrapSource($source, $context, 'callback', '\Icewind\Streams\CallbackWrapper');
@@ -76,6 +82,7 @@ protected function open() {
7682
$this->writeCallback = $context['write'];
7783
$this->closeCallback = $context['close'];
7884
$this->readDirCallBack = $context['readDir'];
85+
$this->preCloseCallback = $context['preClose'];
7986
return true;
8087
}
8188

@@ -90,7 +97,7 @@ public function stream_open($path, $mode, $options, &$opened_path) {
9097
public function stream_read($count) {
9198
$result = parent::stream_read($count);
9299
if (is_callable($this->readCallback)) {
93-
call_user_func($this->readCallback, $count);
100+
call_user_func($this->readCallback, strlen($result));
94101
}
95102
return $result;
96103
}
@@ -104,6 +111,11 @@ public function stream_write($data) {
104111
}
105112

106113
public function stream_close() {
114+
if (is_callable($this->preCloseCallback)) {
115+
call_user_func($this->preCloseCallback, $this->loadContext('callback')['source']);
116+
// prevent further calls by potential PHP 7 GC ghosts
117+
$this->preCloseCallback = null;
118+
}
107119
$result = parent::stream_close();
108120
if (is_callable($this->closeCallback)) {
109121
call_user_func($this->closeCallback);

0 commit comments

Comments
 (0)