@@ -468,6 +468,47 @@ fn file_test_io_read_write_at() {
468468 check ! ( fs:: remove_file( & filename) ) ;
469469}
470470
471+ #[ test]
472+ #[ cfg( unix) ]
473+ fn test_read_buf_at ( ) {
474+ use crate :: os:: unix:: fs:: FileExt ;
475+
476+ let tmpdir = tmpdir ( ) ;
477+ let filename = tmpdir. join ( "file_rt_io_file_test_read_buf_at.txt" ) ;
478+ {
479+ let oo = OpenOptions :: new ( ) . create_new ( true ) . write ( true ) . read ( true ) . clone ( ) ;
480+ let mut file = check ! ( oo. open( & filename) ) ;
481+ check ! ( file. write_all( b"0123456789" ) ) ;
482+ }
483+ {
484+ let mut file = check ! ( File :: open( & filename) ) ;
485+ let mut buf: [ MaybeUninit < u8 > ; 5 ] = [ MaybeUninit :: uninit ( ) ; 5 ] ;
486+ let mut buf = BorrowedBuf :: from ( buf. as_mut_slice ( ) ) ;
487+
488+ check ! ( file. read_buf_exact_at( buf. unfilled( ) , 2 ) ) ;
489+ assert_eq ! ( buf. filled( ) , b"23456" ) ;
490+
491+ // Already full
492+ check ! ( file. read_buf_exact_at( buf. unfilled( ) , 3 ) ) ;
493+ check ! ( file. read_buf_exact_at( buf. unfilled( ) , 10 ) ) ;
494+ assert_eq ! ( buf. filled( ) , b"23456" ) ;
495+ assert_eq ! ( check!( file. stream_position( ) ) , 0 ) ;
496+
497+ // Exact read past eof fails
498+ let err = file. read_buf_exact_at ( buf. clear ( ) . unfilled ( ) , 6 ) . unwrap_err ( ) ;
499+ assert_eq ! ( err. kind( ) , ErrorKind :: UnexpectedEof ) ;
500+ assert_eq ! ( check!( file. stream_position( ) ) , 0 ) ;
501+
502+ // Read past eof is noop
503+ check ! ( file. read_buf_at( buf. clear( ) . unfilled( ) , 10 ) ) ;
504+ assert_eq ! ( buf. filled( ) , b"" ) ;
505+ check ! ( file. read_buf_at( buf. clear( ) . unfilled( ) , 11 ) ) ;
506+ assert_eq ! ( buf. filled( ) , b"" ) ;
507+ assert_eq ! ( check!( file. stream_position( ) ) , 0 ) ;
508+ }
509+ check ! ( fs:: remove_file( & filename) ) ;
510+ }
511+
471512#[ test]
472513#[ cfg( unix) ]
473514fn set_get_unix_permissions ( ) {
@@ -544,6 +585,41 @@ fn file_test_io_seek_read_write() {
544585 check ! ( fs:: remove_file( & filename) ) ;
545586}
546587
588+ #[ test]
589+ #[ cfg( windows) ]
590+ fn test_seek_read_buf ( ) {
591+ use crate :: os:: windows:: fs:: FileExt ;
592+
593+ let tmpdir = tmpdir ( ) ;
594+ let filename = tmpdir. join ( "file_rt_io_file_test_seek_read_buf.txt" ) ;
595+ {
596+ let oo = OpenOptions :: new ( ) . create_new ( true ) . write ( true ) . read ( true ) . clone ( ) ;
597+ let mut file = check ! ( oo. open( & filename) ) ;
598+ check ! ( file. write_all( b"0123456789" ) ) ;
599+ }
600+ {
601+ let mut file = check ! ( File :: open( & filename) ) ;
602+ let mut buf: [ MaybeUninit < u8 > ; 1 ] = [ MaybeUninit :: uninit ( ) ] ;
603+ let mut buf = BorrowedBuf :: from ( buf. as_mut_slice ( ) ) ;
604+
605+ // Seek read
606+ check ! ( buf. seek_read( buf. unfilled( ) , 8 ) ) ;
607+ assert_eq ! ( buf. filled( ) , b"8" ) ;
608+ assert_eq ! ( check!( file. stream_position( ) ) , 9 ) ;
609+
610+ // Empty seek read
611+ check ! ( buf. seek_read( buf. unfilled( ) , 0 ) ) ;
612+ assert_eq ! ( buf. filled( ) , b"8" ) ;
613+ assert_eq ! ( check!( file. stream_position( ) ) , 9 ) ;
614+
615+ // Seek read past eof
616+ check ( buf. seek_read ( buf. clear ( ) . unfilled ( ) , 10 ) ) ;
617+ assert_eq ! ( buf. filled( ) , b"" ) ;
618+ assert_eq ! ( check!( file. stream_position( ) ) , 10 ) ;
619+ }
620+ check ! ( fs:: remove_file( & filename) ) ;
621+ }
622+
547623#[ test]
548624fn file_test_read_buf ( ) {
549625 let tmpdir = tmpdir ( ) ;
0 commit comments