Skip to content

Commit

Permalink
Improve JSONConverter codebase
Browse files Browse the repository at this point in the history
  • Loading branch information
nyamsprod committed Oct 10, 2024
1 parent b4583da commit 9789b05
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions src/JsonConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ public function convert(iterable $records): Iterator
$buffer = [];
while ($records->valid()) {
if ($incr === $this->chunkSize) {
yield $this->format($buffer, $offset).$separator;
yield $this->format($buffer, $offset - $incr).$separator;

$incr = 0;
$buffer = [];
Expand All @@ -429,9 +429,8 @@ public function convert(iterable $records): Iterator
$records->next();
}

$last = $this->format($buffer, $offset);
if ('' !== $last) {
yield $last.$separator;
if ([] !== $buffer) {
yield $this->format($buffer, $offset - $incr).$separator;
}

yield $this->format([$current], $offset++).$end;
Expand Down

0 comments on commit 9789b05

Please sign in to comment.