From f5a9fbf950f250c2a28a05196820bcdf5de25a45 Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Wed, 16 Oct 2024 14:00:07 +0200 Subject: [PATCH] Use consistent keys in split --- src/functions.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/functions.php b/src/functions.php index 17cd3f9..3b33060 100644 --- a/src/functions.php +++ b/src/functions.php @@ -131,6 +131,7 @@ function getStderr(): WritableResourceStream function split(ReadableStream $source, string $delimiter, ?Cancellation $cancellation = null): \Traversable { $buffer = ''; + $k = 0; while (null !== $chunk = $source->read($cancellation)) { $buffer .= $chunk; @@ -138,11 +139,13 @@ function split(ReadableStream $source, string $delimiter, ?Cancellation $cancell $split = \explode($delimiter, $buffer); $buffer = \array_pop($split); - yield from $split; + foreach ($split as $v) { + yield $k++ => $v; + } } if ($buffer !== '') { - yield $buffer; + yield $k => $buffer; } }