Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
danog committed Oct 16, 2024
1 parent f5a9fbf commit 464d2ba
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,21 +131,21 @@ function getStderr(): WritableResourceStream
function split(ReadableStream $source, string $delimiter, ?Cancellation $cancellation = null): \Traversable
{
$buffer = '';
$k = 0;

while (null !== $chunk = $source->read($cancellation)) {
$buffer .= $chunk;

$split = \explode($delimiter, $buffer);
$buffer = \array_pop($split);

// Don't use yield from to avoid reusing the keys from $split
foreach ($split as $v) {
yield $k++ => $v;
yield $v;
}
}

if ($buffer !== '') {
yield $k => $buffer;
yield $buffer;
}
}

Expand Down

0 comments on commit 464d2ba

Please sign in to comment.