@@ -391,14 +391,13 @@ impl RecordSet {
391391
392392 // Split out record processing to separate function
393393 fn process_records < R : io:: Read > ( & mut self , reader : & mut Reader < R > ) -> Result < bool , Error > {
394- let mut available_complete = self . newlines . len ( ) / 4 ;
395-
396394 // At EOF, check if we have exactly 3 newlines remaining (final record without trailing newline)
397- let has_final_incomplete = reader. eof && ( self . newlines . len ( ) % 4 == 3 ) ;
398- if has_final_incomplete {
399- available_complete += 1 ;
395+ if reader. eof && self . newlines . len ( ) % 4 == 3 {
396+ // If we just have 3 lines (no trailing newline), add a synthetic newline to the buffer
397+ self . buffer . push ( b'\n' ) ;
398+ self . find_newlines ( self . buffer . len ( ) ) ;
400399 }
401-
400+ let available_complete = self . newlines . len ( ) / 4 ;
402401 let records_to_process = available_complete. min ( self . capacity ) ;
403402
404403 if records_to_process > 0 {
@@ -409,7 +408,7 @@ impl RecordSet {
409408 // Process complete records with 4 newlines
410409 self . newlines
411410 . chunks_exact ( 4 )
412- . take ( records_to_process. saturating_sub ( if has_final_incomplete { 1 } else { 0 } ) )
411+ . take ( records_to_process)
413412 . for_each ( |chunk| {
414413 let ( seq_start, sep_start, qual_start, end) =
415414 ( chunk[ 0 ] , chunk[ 1 ] , chunk[ 2 ] , chunk[ 3 ] ) ;
@@ -425,30 +424,7 @@ impl RecordSet {
425424 record_start = end;
426425 last_end = end;
427426 } ) ;
428-
429- // Handle final record with only 3 newlines at EOF
430- if has_final_incomplete {
431- let remaining = self . newlines . len ( ) % 4 ;
432- let start_idx = self . newlines . len ( ) - remaining;
433- let ( seq_start, sep_start, qual_start) = (
434- self . newlines [ start_idx] ,
435- self . newlines [ start_idx + 1 ] ,
436- self . newlines [ start_idx + 2 ] ,
437- ) ;
438-
439- self . positions . push ( Positions {
440- start : record_start,
441- seq_start,
442- sep_start,
443- qual_start,
444- qual_end : self . buffer . len ( ) ,
445- end : self . buffer . len ( ) ,
446- } ) ;
447- last_end = self . buffer . len ( ) ;
448- }
449-
450427 self . update_avg_record_size ( last_end) ;
451-
452428 // Move remaining partial data to overflow
453429 reader. overflow . extend_from_slice ( & self . buffer [ last_end..] ) ;
454430 self . buffer . truncate ( last_end) ;
@@ -729,9 +705,9 @@ mod tests {
729705 assert ! ( record_set. fill( & mut reader) . unwrap( ) ) ;
730706
731707 for record in record_set. iter ( ) {
732- println ! ( "Record: {:?}" , record) ;
708+ let record = record. unwrap ( ) ;
709+ assert_eq ! ( record. seq( ) . len( ) , record. qual( ) . unwrap( ) . len( ) ) ;
733710 }
734-
735711 assert ! ( record_set. iter( ) . next( ) . unwrap( ) . is_ok( ) ) ;
736712 }
737713
0 commit comments