@@ -6,10 +6,13 @@ use std::{
6
6
} ;
7
7
8
8
use async_trait:: async_trait;
9
- use bytes:: BytesMut ;
9
+ use bytes:: { BufMut , BytesMut } ;
10
10
use dashmap:: DashSet ;
11
11
use dmds:: IoHandle ;
12
- use tokio:: { fs:: File , io:: BufReader } ;
12
+ use tokio:: {
13
+ fs:: File ,
14
+ io:: { AsyncReadExt , BufReader } ,
15
+ } ;
13
16
14
17
#[ cfg( test) ]
15
18
mod tests;
@@ -38,7 +41,7 @@ impl IoHandle for FsHandle {
38
41
async fn read_chunk < const DIMS : usize > (
39
42
& self ,
40
43
pos : [ usize ; DIMS ] ,
41
- ) -> std:: io:: Result < Self :: Read < ' _ > > {
44
+ ) -> std:: io:: Result < ( u32 , Self :: Read < ' _ > ) > {
42
45
let path = self . path ( & pos) ;
43
46
let result = File :: open ( & path) . await ;
44
47
@@ -50,11 +53,17 @@ impl IoHandle for FsHandle {
50
53
self . invalid_chunks . insert ( Box :: new ( pos) ) ;
51
54
}
52
55
}
53
-
54
- Ok ( FsReader {
55
- _handle : self ,
56
- file : BufReader :: new ( result?) ,
57
- } )
56
+ let mut file = BufReader :: new ( result?) ;
57
+ let mut buf = [ 0_u8 ; 4 ] ;
58
+ file. read_exact ( & mut & mut buf[ ..] ) . await ?;
59
+
60
+ Ok ( (
61
+ u32:: from_be_bytes ( buf) ,
62
+ FsReader {
63
+ _handle : self ,
64
+ file,
65
+ } ,
66
+ ) )
58
67
}
59
68
}
60
69
@@ -76,6 +85,7 @@ impl FsHandle {
76
85
chunk : & dmds:: Chunk < T , DIMS > ,
77
86
) -> std:: io:: Result < ( ) > {
78
87
let mut buf = BytesMut :: new ( ) ;
88
+ buf. put_u32 ( T :: VERSION ) ;
79
89
chunk. write_buf ( & mut buf) . await ?;
80
90
let buf = buf. freeze ( ) ;
81
91
0 commit comments