From a1ec78bf0dc93d0e05e5f066f1949dc3baecea06 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 28 Apr 2024 14:44:51 +0200 Subject: Adding upstream version 0.20.0. Signed-off-by: Daniel Baumann --- vendor/gipfl/stream/composer.json | 26 +++++++ vendor/gipfl/stream/src/BufferedLineReader.php | 100 +++++++++++++++++++++++++ 2 files changed, 126 insertions(+) create mode 100644 vendor/gipfl/stream/composer.json create mode 100644 vendor/gipfl/stream/src/BufferedLineReader.php (limited to 'vendor/gipfl/stream') diff --git a/vendor/gipfl/stream/composer.json b/vendor/gipfl/stream/composer.json new file mode 100644 index 0000000..3bbcb6a --- /dev/null +++ b/vendor/gipfl/stream/composer.json @@ -0,0 +1,26 @@ +{ + "name": "gipfl/stream", + "description": "Helpful ReactPHP stream utility classes", + "type": "library", + "license": "MIT", + "autoload": { + "psr-4": { + "gipfl\\Stream\\": "src/" + } + }, + "authors": [ + { + "name": "Thomas Gelf", + "email": "thomas@gelf.net" + } + ], + "require": { + "react/event-loop": ">=1.0", + "react/stream": ">=1.0" + }, + "require-dev": { + "gipfl/test": ">=0.1.1", + "phpunit/phpunit": "^9.3 || ^7.5 || ^6.5 || ^5.7", + "squizlabs/php_codesniffer": "^3.6" + } +} diff --git a/vendor/gipfl/stream/src/BufferedLineReader.php b/vendor/gipfl/stream/src/BufferedLineReader.php new file mode 100644 index 0000000..bd43155 --- /dev/null +++ b/vendor/gipfl/stream/src/BufferedLineReader.php @@ -0,0 +1,100 @@ +loop = $loop; + $this->separator = $separator; + $this->separatorLength = strlen($separator); + $this->process = function () { + $this->processBuffer(); + }; + } + + protected function processBuffer() + { + $lastPos = 0; + while (false !== ($pos = strpos($this->buffer, $this->separator, $lastPos))) { + $this->emit('line', [substr($this->buffer, $lastPos, $pos - $lastPos)]); + $lastPos = $pos + $this->separatorLength; + } + if ($lastPos !== 0) { + $this->buffer = substr($this->buffer, $lastPos); + } + } + + public function isWritable() + { + return $this->writable; + } + + public function write($data) + { + if (! $this->writable) { + return false; + } + $this->buffer .= $data; + if (strpos($data, $this->separator) !== false) { + $this->loop->futureTick($this->process); + } + + return true; + } + + public function end($data = null) + { + if ($data !== null) { + $this->buffer .= $data; + } + $this->close(); + } + + public function close() + { + $this->writable = false; + $this->processBuffer(); + $remainingBuffer = $this->buffer; + $this->buffer = ''; + if ($length = strlen($remainingBuffer)) { + $this->emit('error', [new \Exception(sprintf( + 'There are %d unprocessed bytes in our buffer: %s', + $length, + substr($remainingBuffer, 0, 64) + ))]); + } + $this->emit('close'); + } +} -- cgit v1.2.3