File tree Expand file tree Collapse file tree 1 file changed +13
-7
lines changed Expand file tree Collapse file tree 1 file changed +13
-7
lines changed Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments