Read streamed output line by line, not via buffer

This way the code doesn't wait for a buffer to be filled, and we don't need to
implement logic ourselves that is provided by a present library already.

Signed-off-by: Pablo Zmdl <pablo@nextcloud.com>
This commit is contained in:
Pablo Zmdl
2026-05-28 12:38:01 +02:00
parent 7741123e89
commit 22044fde9c

View File

@@ -11,6 +11,7 @@ use AIO\Data\ConfigurationManager;
use AIO\Data\DataConst;
use GuzzleHttp\Client;
use GuzzleHttp\Exception\RequestException;
use GuzzleHttp\Psr7\Utils;
use http\Env\Response;
readonly class DockerActionManager {
@@ -842,22 +843,12 @@ readonly class DockerActionManager {
if ($outputCallback !== null) {
$body = $startResponse->getBody();
$buffer = '';
while (!$body->eof()) {
$chunk = $body->read(1024);
$buffer .= $chunk;
while (($pos = strpos($buffer, "\n")) !== false) {
$line = substr($buffer, 0, $pos);
$buffer = substr($buffer, $pos + 1);
$line = rtrim($line, "\r");
if ($line !== '') {
$outputCallback($line);
}
$line = rtrim(Utils::readLine($pullBody), "\r");;
if ($line !== '') {
$outputCallback($line);
}
}
if (trim($buffer) !== '') {
$outputCallback(trim($buffer));
}
}
}