Skip to content

Commit

Permalink
bump dmds to 0.2
Browse files Browse the repository at this point in the history
  • Loading branch information
JieningYu committed Dec 20, 2023
1 parent 845809d commit e949e84
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
4 changes: 2 additions & 2 deletions tokio-fs/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "dmds-tokio-fs"
version = "0.1.0"
version = "0.2.0"
edition = "2021"
authors = ["JieningYu <[email protected]>"]
description = "Dmds I/O handler interacts with the filesystem using Tokio"
Expand All @@ -15,7 +15,7 @@ maintenance = { status = "actively-developed" }
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
dmds = "0.1"
dmds = "0.2"
async-trait = "0.1"
tokio = { version = "1.34", features = ["fs", "io-util", "time", "rt"] }
futures = { version = "0.3", features = ["executor"] }
Expand Down
26 changes: 18 additions & 8 deletions tokio-fs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@ use std::{
};

use async_trait::async_trait;
use bytes::BytesMut;
use bytes::{BufMut, BytesMut};
use dashmap::DashSet;
use dmds::IoHandle;
use tokio::{fs::File, io::BufReader};
use tokio::{
fs::File,
io::{AsyncReadExt, BufReader},
};

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

Expand All @@ -50,11 +53,17 @@ impl IoHandle for FsHandle {
self.invalid_chunks.insert(Box::new(pos));
}
}

Ok(FsReader {
_handle: self,
file: BufReader::new(result?),
})
let mut file = BufReader::new(result?);
let mut buf = [0_u8; 4];
file.read_exact(&mut &mut buf[..]).await?;

Ok((
u32::from_be_bytes(buf),
FsReader {
_handle: self,
file,
},
))
}
}

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

Expand Down

0 comments on commit e949e84

Please sign in to comment.