Skip to content

Commit e53f458

Browse files
committed
fix splCsvReader
1 parent 337ae5f commit e53f458

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

src/Readers/SplCsvReader.php

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -238,16 +238,22 @@ public function nextRecord(): array|false
238238
return false;
239239
}
240240

241-
$filePosition = $nextPosition;
242-
if ($this->getConfig()->hasHeader()) {
243-
$filePosition++; // Skip header line
244-
}
245-
246241
try {
247-
$reader->seek($filePosition);
242+
// For the first read, position the reader correctly
243+
if ($this->position === -1) {
244+
$reader->rewind();
245+
if ($this->getConfig()->hasHeader()) {
246+
$reader->current(); // Read header
247+
$reader->next(); // Move past header
248+
}
249+
} else {
250+
// For subsequent reads, just advance sequentially (much faster than seek)
251+
$reader->next();
252+
}
253+
248254
$record = $reader->current();
249255

250-
if ($record === false || $record === null || ! is_array($record)) {
256+
if ($record === false || $record === null || ! is_array($record) || $this->isInvalidRecord($record)) {
251257
return false;
252258
}
253259

0 commit comments

Comments
 (0)