@@ -3,19 +3,11 @@ use std::fs;
33use std:: io;
44use std:: io:: Read ;
55#[ cfg( target_os = "windows" ) ]
6- use std:: io:: { Error , ErrorKind } ;
6+ use std:: io:: { Seek , SeekFrom } ;
77#[ cfg( target_os = "linux" ) ]
88use std:: os:: unix:: fs:: FileExt ;
9- #[ cfg( target_os = "windows" ) ]
10- use std:: os:: windows:: io:: AsRawHandle ;
119use std:: path:: Path ;
1210use std:: str;
13- #[ cfg( target_os = "windows" ) ]
14- use windows:: Win32 :: Foundation :: HANDLE ;
15- #[ cfg( target_os = "windows" ) ]
16- use windows:: Win32 :: Storage :: FileSystem :: ReadFile ;
17- #[ cfg( target_os = "windows" ) ]
18- use windows:: Win32 :: System :: IO :: OVERLAPPED ;
1911use zstd:: Decoder ;
2012use zstd:: dict:: DecoderDictionary ;
2113
@@ -27,46 +19,9 @@ fn read_exact_at(file: &fs::File, buffer: &mut Vec<u8>, offset: u64) -> io::Resu
2719}
2820
2921#[ cfg( target_os = "windows" ) ]
30- fn read_exact_at ( file : & fs:: File , buffer : & mut Vec < u8 > , offset : u64 ) -> io:: Result < ( ) > {
31- if buffer. is_empty ( ) {
32- return Ok ( ( ) ) ;
33- }
34-
35- // Prepare OVERLAPPED structure with the offset
36- let mut overlapped = OVERLAPPED :: default ( ) ;
37- overlapped. Anonymous . Anonymous . Offset = offset as u32 ;
38- overlapped. Anonymous . Anonymous . OffsetHigh = ( offset >> 32 ) as u32 ;
39-
40- let handle = HANDLE ( file. as_raw_handle ( ) ) ;
41-
42- let mut total_read = 0 ;
43- while total_read < buffer. len ( ) {
44- let mut bytes_read: u32 = 0 ;
45- let success = unsafe {
46- ReadFile (
47- handle,
48- Some ( & mut buffer[ total_read..] ) ,
49- Some ( & mut bytes_read) ,
50- Some ( & mut overlapped) ,
51- )
52- } ;
53-
54- if !success. is_ok ( ) {
55- return Err ( Error :: last_os_error ( ) ) ;
56- }
57-
58- if bytes_read == 0 {
59- return Err ( Error :: new ( ErrorKind :: UnexpectedEof , "Unexpected EOF" ) ) ;
60- }
61-
62- total_read += bytes_read as usize ;
63- // Advance offset in OVERLAPPED for next chunk
64- let new_offset = offset + total_read as u64 ;
65- overlapped. Anonymous . Anonymous . Offset = new_offset as u32 ;
66- overlapped. Anonymous . Anonymous . OffsetHigh = ( new_offset >> 32 ) as u32 ;
67- }
68-
69- Ok ( ( ) )
22+ fn read_exact_at ( mut file : & fs:: File , buffer : & mut Vec < u8 > , offset : u64 ) -> io:: Result < ( ) > {
23+ file. seek ( SeekFrom :: Start ( offset) ) ?;
24+ file. read_exact ( buffer)
7025}
7126
7227pub struct Reader {
0 commit comments