summaryrefslogtreecommitdiff
path: root/src/store.rs
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2020-10-14 08:57:04 +0300
committerLars Wirzenius <liw@liw.fi>2020-10-14 08:57:04 +0300
commitb58261f996883a4f63487a50f48cbb20cf7d8fdb (patch)
tree4e6cec82e18ab73482ddd498e0efb480f8978b1a /src/store.rs
parentafebc46461edea5e14d5b63a10631af9660a3439 (diff)
downloadobnam2-b58261f996883a4f63487a50f48cbb20cf7d8fdb.tar.gz
refactor: move chunk metadata out of chunk struct
Diffstat (limited to 'src/store.rs')
-rw-r--r--src/store.rs8
1 files changed, 4 insertions, 4 deletions
diff --git a/src/store.rs b/src/store.rs
index 873b8f2..bad52ce 100644
--- a/src/store.rs
+++ b/src/store.rs
@@ -26,8 +26,8 @@ impl Store {
}
/// Save a chunk into a store.
- pub fn save(&self, id: &ChunkId, chunk: &Chunk) -> anyhow::Result<()> {
- std::fs::write(&self.filename(id, "meta"), chunk.meta().to_json())?;
+ pub fn save(&self, id: &ChunkId, meta: &ChunkMeta, chunk: &Chunk) -> anyhow::Result<()> {
+ std::fs::write(&self.filename(id, "meta"), meta.to_json())?;
std::fs::write(&self.filename(id, "data"), chunk.data())?;
Ok(())
}
@@ -39,10 +39,10 @@ impl Store {
}
/// Load a chunk from a store.
- pub fn load(&self, id: &ChunkId) -> anyhow::Result<Chunk> {
+ pub fn load(&self, id: &ChunkId) -> anyhow::Result<(ChunkMeta, Chunk)> {
let meta = self.load_meta(id)?;
let data = std::fs::read(&self.filename(id, "data"))?;
- Ok(Chunk::new(meta, data))
+ Ok((meta, Chunk::new(data)))
}
/// Delete a chunk from a store.