Skip to content

Commit e949e84

Browse files
committed
bump dmds to 0.2
1 parent 845809d commit e949e84

File tree

2 files changed

+20
-10
lines changed

2 files changed

+20
-10
lines changed

tokio-fs/Cargo.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "dmds-tokio-fs"
3-
version = "0.1.0"
3+
version = "0.2.0"
44
edition = "2021"
55
authors = ["JieningYu <[email protected]>"]
66
description = "Dmds I/O handler interacts with the filesystem using Tokio"
@@ -15,7 +15,7 @@ maintenance = { status = "actively-developed" }
1515
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
1616

1717
[dependencies]
18-
dmds = "0.1"
18+
dmds = "0.2"
1919
async-trait = "0.1"
2020
tokio = { version = "1.34", features = ["fs", "io-util", "time", "rt"] }
2121
futures = { version = "0.3", features = ["executor"] }

tokio-fs/src/lib.rs

+18-8
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,13 @@ use std::{
66
};
77

88
use async_trait::async_trait;
9-
use bytes::BytesMut;
9+
use bytes::{BufMut, BytesMut};
1010
use dashmap::DashSet;
1111
use dmds::IoHandle;
12-
use tokio::{fs::File, io::BufReader};
12+
use tokio::{
13+
fs::File,
14+
io::{AsyncReadExt, BufReader},
15+
};
1316

1417
#[cfg(test)]
1518
mod tests;
@@ -38,7 +41,7 @@ impl IoHandle for FsHandle {
3841
async fn read_chunk<const DIMS: usize>(
3942
&self,
4043
pos: [usize; DIMS],
41-
) -> std::io::Result<Self::Read<'_>> {
44+
) -> std::io::Result<(u32, Self::Read<'_>)> {
4245
let path = self.path(&pos);
4346
let result = File::open(&path).await;
4447

@@ -50,11 +53,17 @@ impl IoHandle for FsHandle {
5053
self.invalid_chunks.insert(Box::new(pos));
5154
}
5255
}
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+
))
5867
}
5968
}
6069

@@ -76,6 +85,7 @@ impl FsHandle {
7685
chunk: &dmds::Chunk<T, DIMS>,
7786
) -> std::io::Result<()> {
7887
let mut buf = BytesMut::new();
88+
buf.put_u32(T::VERSION);
7989
chunk.write_buf(&mut buf).await?;
8090
let buf = buf.freeze();
8191

0 commit comments

Comments
 (0)