@@ -490,6 +490,47 @@ fn file_test_io_read_write_at() {
490490 check ! ( fs:: remove_file( & filename) ) ;
491491}
492492
493+ #[ test]
494+ #[ cfg( unix) ]
495+ fn test_read_buf_at ( ) {
496+ use crate :: os:: unix:: fs:: FileExt ;
497+
498+ let tmpdir = tmpdir ( ) ;
499+ let filename = tmpdir. join ( "file_rt_io_file_test_read_buf_at.txt" ) ;
500+ {
501+ let oo = OpenOptions :: new ( ) . create_new ( true ) . write ( true ) . read ( true ) . clone ( ) ;
502+ let mut file = check ! ( oo. open( & filename) ) ;
503+ check ! ( file. write_all( b"0123456789" ) ) ;
504+ }
505+ {
506+ let mut file = check ! ( File :: open( & filename) ) ;
507+ let mut buf: [ MaybeUninit < u8 > ; 5 ] = [ MaybeUninit :: uninit ( ) ; 5 ] ;
508+ let mut buf = BorrowedBuf :: from ( buf. as_mut_slice ( ) ) ;
509+
510+ check ! ( file. read_buf_exact_at( buf. unfilled( ) , 2 ) ) ;
511+ assert_eq ! ( buf. filled( ) , b"23456" ) ;
512+
513+ // Already full
514+ check ! ( file. read_buf_exact_at( buf. unfilled( ) , 3 ) ) ;
515+ check ! ( file. read_buf_exact_at( buf. unfilled( ) , 10 ) ) ;
516+ assert_eq ! ( buf. filled( ) , b"23456" ) ;
517+ assert_eq ! ( check!( file. stream_position( ) ) , 0 ) ;
518+
519+ // Exact read past eof fails
520+ let err = file. read_buf_exact_at ( buf. clear ( ) . unfilled ( ) , 6 ) . unwrap_err ( ) ;
521+ assert_eq ! ( err. kind( ) , ErrorKind :: UnexpectedEof ) ;
522+ assert_eq ! ( check!( file. stream_position( ) ) , 0 ) ;
523+
524+ // Read past eof is noop
525+ check ! ( file. read_buf_at( buf. clear( ) . unfilled( ) , 10 ) ) ;
526+ assert_eq ! ( buf. filled( ) , b"" ) ;
527+ check ! ( file. read_buf_at( buf. clear( ) . unfilled( ) , 11 ) ) ;
528+ assert_eq ! ( buf. filled( ) , b"" ) ;
529+ assert_eq ! ( check!( file. stream_position( ) ) , 0 ) ;
530+ }
531+ check ! ( fs:: remove_file( & filename) ) ;
532+ }
533+
493534#[ test]
494535#[ cfg( unix) ]
495536fn set_get_unix_permissions ( ) {
@@ -566,6 +607,41 @@ fn file_test_io_seek_read_write() {
566607 check ! ( fs:: remove_file( & filename) ) ;
567608}
568609
610+ #[ test]
611+ #[ cfg( windows) ]
612+ fn test_seek_read_buf ( ) {
613+ use crate :: os:: windows:: fs:: FileExt ;
614+
615+ let tmpdir = tmpdir ( ) ;
616+ let filename = tmpdir. join ( "file_rt_io_file_test_seek_read_buf.txt" ) ;
617+ {
618+ let oo = OpenOptions :: new ( ) . create_new ( true ) . write ( true ) . read ( true ) . clone ( ) ;
619+ let mut file = check ! ( oo. open( & filename) ) ;
620+ check ! ( file. write_all( b"0123456789" ) ) ;
621+ }
622+ {
623+ let mut file = check ! ( File :: open( & filename) ) ;
624+ let mut buf: [ MaybeUninit < u8 > ; 1 ] = [ MaybeUninit :: uninit ( ) ] ;
625+ let mut buf = BorrowedBuf :: from ( buf. as_mut_slice ( ) ) ;
626+
627+ // Seek read
628+ check ! ( file. seek_read_buf( buf. unfilled( ) , 8 ) ) ;
629+ assert_eq ! ( buf. filled( ) , b"8" ) ;
630+ assert_eq ! ( check!( file. stream_position( ) ) , 9 ) ;
631+
632+ // Empty seek read
633+ check ! ( file. seek_read_buf( buf. unfilled( ) , 0 ) ) ;
634+ assert_eq ! ( buf. filled( ) , b"8" ) ;
635+ assert_eq ! ( check!( file. stream_position( ) ) , 0 ) ;
636+
637+ // Seek read past eof
638+ check ! ( file. seek_read_buf( buf. clear( ) . unfilled( ) , 10 ) ) ;
639+ assert_eq ! ( buf. filled( ) , b"" ) ;
640+ assert_eq ! ( check!( file. stream_position( ) ) , 10 ) ;
641+ }
642+ check ! ( fs:: remove_file( & filename) ) ;
643+ }
644+
569645#[ test]
570646fn file_test_read_buf ( ) {
571647 let tmpdir = tmpdir ( ) ;
0 commit comments