@@ -452,6 +452,47 @@ fn file_test_io_read_write_at() {
452452 check ! ( fs:: remove_file( & filename) ) ;
453453}
454454
455+ #[ test]
456+ #[ cfg( unix) ]
457+ fn test_read_buf_at ( ) {
458+ use crate :: os:: unix:: fs:: FileExt ;
459+
460+ let tmpdir = tmpdir ( ) ;
461+ let filename = tmpdir. join ( "file_rt_io_file_test_read_buf_at.txt" ) ;
462+ {
463+ let oo = OpenOptions :: new ( ) . create_new ( true ) . write ( true ) . read ( true ) . clone ( ) ;
464+ let mut file = check ! ( oo. open( & filename) ) ;
465+ check ! ( file. write_all( b"0123456789" ) ) ;
466+ }
467+ {
468+ let mut file = check ! ( File :: open( & filename) ) ;
469+ let mut buf: [ MaybeUninit < u8 > ; 5 ] = [ MaybeUninit :: uninit ( ) ; 5 ] ;
470+ let mut buf = BorrowedBuf :: from ( buf. as_mut_slice ( ) ) ;
471+
472+ check ! ( file. read_buf_exact_at( buf. unfilled( ) , 2 ) ) ;
473+ assert_eq ! ( buf. filled( ) , b"23456" ) ;
474+
475+ // Already full
476+ check ! ( file. read_buf_exact_at( buf. unfilled( ) , 3 ) ) ;
477+ check ! ( file. read_buf_exact_at( buf. unfilled( ) , 10 ) ) ;
478+ assert_eq ! ( buf. filled( ) , b"23456" ) ;
479+ assert_eq ! ( check!( file. stream_position( ) ) , 0 ) ;
480+
481+ // Exact read past eof fails
482+ let err = file. read_buf_exact_at ( buf. clear ( ) . unfilled ( ) , 6 ) . unwrap_err ( ) ;
483+ assert_eq ! ( err. kind( ) , ErrorKind :: UnexpectedEof ) ;
484+ assert_eq ! ( check!( file. stream_position( ) ) , 0 ) ;
485+
486+ // Read past eof is noop
487+ check ! ( file. read_buf_at( buf. clear( ) . unfilled( ) , 10 ) ) ;
488+ assert_eq ! ( buf. filled( ) , b"" ) ;
489+ check ! ( file. read_buf_at( buf. clear( ) . unfilled( ) , 11 ) ) ;
490+ assert_eq ! ( buf. filled( ) , b"" ) ;
491+ assert_eq ! ( check!( file. stream_position( ) ) , 0 ) ;
492+ }
493+ check ! ( fs:: remove_file( & filename) ) ;
494+ }
495+
455496#[ test]
456497#[ cfg( unix) ]
457498fn set_get_unix_permissions ( ) {
@@ -528,6 +569,41 @@ fn file_test_io_seek_read_write() {
528569 check ! ( fs:: remove_file( & filename) ) ;
529570}
530571
572+ #[ test]
573+ #[ cfg( windows) ]
574+ fn test_seek_read_buf ( ) {
575+ use crate :: os:: windows:: fs:: FileExt ;
576+
577+ let tmpdir = tmpdir ( ) ;
578+ let filename = tmpdir. join ( "file_rt_io_file_test_seek_read_buf.txt" ) ;
579+ {
580+ let oo = OpenOptions :: new ( ) . create_new ( true ) . write ( true ) . read ( true ) . clone ( ) ;
581+ let mut file = check ! ( oo. open( & filename) ) ;
582+ check ! ( file. write_all( b"0123456789" ) ) ;
583+ }
584+ {
585+ let mut file = check ! ( File :: open( & filename) ) ;
586+ let mut buf: [ MaybeUninit < u8 > ; 1 ] = [ MaybeUninit :: uninit ( ) ] ;
587+ let mut buf = BorrowedBuf :: from ( buf. as_mut_slice ( ) ) ;
588+
589+ // Seek read
590+ check ! ( buf. seek_read( buf. unfilled( ) , 8 ) ) ;
591+ assert_eq ! ( buf. filled( ) , b"8" ) ;
592+ assert_eq ! ( check!( file. stream_position( ) ) , 9 ) ;
593+
594+ // Empty seek read
595+ check ! ( buf. seek_read( buf. unfilled( ) , 0 ) ) ;
596+ assert_rq ! ( buf. filled( ) , b"8" ) ;
597+ assert_eq ! ( check!( file. stream_position( ) ) , 9 ) ;
598+
599+ // Seek read past eof
600+ check ( buf. seek_read ( buf. clear ( ) . unfilled ( ) , 10 ) ) ;
601+ assert_eq ! ( buf. filled( ) , b"" ) ;
602+ assert_eq ! ( check!( file. stream_position( ) ) , 9 ) ;
603+ }
604+ check ! ( fs:: remove_file( & filename) ) ;
605+ }
606+
531607#[ test]
532608fn file_test_read_buf ( ) {
533609 let tmpdir = tmpdir ( ) ;
0 commit comments