From 85de9b5dd4804b9d9fcb3600047c9990b8836f96 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20L=C3=BCck?= Date: Fri, 18 Aug 2017 14:12:43 +0200 Subject: [PATCH 1/3] Forward compatibility with Stream v0.5 semantics --- composer.json | 2 +- src/TransformStream.php | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/composer.json b/composer.json index ded4392..2eb906f 100644 --- a/composer.json +++ b/composer.json @@ -12,7 +12,7 @@ ], "require": { "php": ">=5.3", - "react/stream": "~0.4.3", + "react/stream": "^0.5 || ^0.4.3", "clue/stream-filter": "~1.3" }, "require-dev": { diff --git a/src/TransformStream.php b/src/TransformStream.php index f74cf70..2b3d386 100644 --- a/src/TransformStream.php +++ b/src/TransformStream.php @@ -20,7 +20,7 @@ class TransformStream extends EventEmitter implements DuplexStreamInterface public function write($data) { if (!$this->writable || $data === '') { - return; + return false; } try { @@ -57,7 +57,7 @@ public function close() $this->readable = false; $this->writable = false; - $this->emit('close', array($this)); + $this->emit('close'); } public function isReadable() @@ -98,10 +98,10 @@ public function pipe(WritableStreamInterface $dest, array $options = array()) */ protected function forwardData($data) { - if (!$this->readable && $data !== '') { + if (!$this->readable) { return; } - $this->emit('data', array($data, $this)); + $this->emit('data', array($data)); } /** @@ -121,7 +121,7 @@ protected function forwardEnd() $this->readable = false; $this->writable = false; - $this->emit('end', array($this)); + $this->emit('end'); $this->close(); } @@ -143,7 +143,7 @@ protected function forwardError(Exception $error) $this->readable = false; $this->writable = false; - $this->emit('error', array($error, $this)); + $this->emit('error', array($error)); $this->close(); } From eecd4dfd54140e66aeee6c39809de21b99489eca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20L=C3=BCck?= Date: Fri, 18 Aug 2017 14:34:25 +0200 Subject: [PATCH 2/3] Update to Stream v0.6 API and forward compatibility with Stream v1.0 --- README.md | 2 +- composer.json | 8 ++++---- examples/gunzip.php | 4 ++-- examples/gzip.php | 4 ++-- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index fc7ad49..6fd6c00 100644 --- a/README.md +++ b/README.md @@ -34,7 +34,7 @@ each individual file chunk: ```php $loop = React\EventLoop\Factory::create(); -$stream = new Stream(fopen('access.log.gz', 'r'), $loop); +$stream = new React\Stream\ReadableResourceStream(fopen('access.log.gz', 'r'), $loop); $decompressor = ZlibFilterStream::createGzipDecompressor(); diff --git a/composer.json b/composer.json index 2eb906f..6c3b787 100644 --- a/composer.json +++ b/composer.json @@ -12,12 +12,12 @@ ], "require": { "php": ">=5.3", - "react/stream": "^0.5 || ^0.4.3", - "clue/stream-filter": "~1.3" + "clue/stream-filter": "~1.3", + "react/stream": "^1.0 || ^0.7 || ^0.6" }, "require-dev": { - "react/event-loop": "~0.4.0|~0.3.0", - "phpunit/phpunit": "^5.0 || ^4.8" + "phpunit/phpunit": "^5.0 || ^4.8", + "react/event-loop": "^1.0 || ^0.5 || ^0.4 || ^0.3" }, "suggest": { "ext-zlib": "Requires ext-zlib extension" diff --git a/examples/gunzip.php b/examples/gunzip.php index 785010e..a5e2c62 100644 --- a/examples/gunzip.php +++ b/examples/gunzip.php @@ -4,8 +4,8 @@ $loop = React\EventLoop\Factory::create(); -$in = new React\Stream\Stream(STDIN, $loop); -$out = new React\Stream\Stream(STDOUT, $loop); +$in = new React\Stream\ReadableResourceStream(STDIN, $loop); +$out = new React\Stream\WritableResourceStream(STDOUT, $loop); $decompressor = Clue\React\Zlib\ZlibFilterStream::createGzipDecompressor(); $in->pipe($decompressor)->pipe($out); diff --git a/examples/gzip.php b/examples/gzip.php index bdf748e..8f943a3 100644 --- a/examples/gzip.php +++ b/examples/gzip.php @@ -4,8 +4,8 @@ $loop = React\EventLoop\Factory::create(); -$in = new React\Stream\Stream(STDIN, $loop); -$out = new React\Stream\Stream(STDOUT, $loop); +$in = new React\Stream\ReadableResourceStream(STDIN, $loop); +$out = new React\Stream\WritableResourceStream(STDOUT, $loop); $compressor = Clue\React\Zlib\ZlibFilterStream::createGzipCompressor(1); $in->pipe($compressor)->pipe($out); From ddf1984c57ae99bcb2cbeac4616273063a6e7d9b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20L=C3=BCck?= Date: Fri, 18 Aug 2017 14:55:25 +0200 Subject: [PATCH 3/3] Updating Stream dependency fixes legacy PHP < 5.4 issues --- README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/README.md b/README.md index 6fd6c00..edef077 100644 --- a/README.md +++ b/README.md @@ -141,7 +141,6 @@ These inconsistencies exist in the underlying PHP engines and there's little we * PHP 7 only: Compressing an empty string does not emit any data (not a valid compression stream) * HHVM only: does not currently support the GZIP and ZLIB format at all (and does not raise an error) * HHVM only: The [`zlib.deflate` filter function](https://github.com/facebook/hhvm/blob/fee8ae39ce395c7b9b8910dfde6f22a7745aea83/hphp/system/php/stream/default-filters.php#L77) buffers the whole string. This means that compressing a stream of 100 MB actually stores the whole string in memory before invoking the underlying compression algorithm. -* PHP 5.3 only: Tends to SEGFAULT occasionally on shutdown? Our test suite contains several test cases that exhibit these issues. If you feel some test case is missing or outdated, we're happy to accept PRs! :)