diff options
author | Lars Wirzenius <liw@liw.fi> | 2021-06-04 06:35:14 +0000 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2021-06-04 06:35:14 +0000 |
commit | f2a274ee1291531c1154176bca5b9a47e9c234bd (patch) | |
tree | 6721b515739c6e5f9236ffd6f4ecc2dfecc471d2 /src/store.rs | |
parent | cb33088dbedf4b772013f83b8226047cc4355dd2 (diff) | |
parent | 9c2590d2428f0d3de882686ec2ec5832e7123c62 (diff) | |
download | obnam2-f2a274ee1291531c1154176bca5b9a47e9c234bd.tar.gz |
Merge branch 'aead' into 'main'
add encryption of individual chunks
Closes #110
See merge request larswirzenius/obnam!146
Diffstat (limited to 'src/store.rs')
-rw-r--r-- | src/store.rs | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/src/store.rs b/src/store.rs index fca2c13..bccecc7 100644 --- a/src/store.rs +++ b/src/store.rs @@ -1,6 +1,5 @@ use crate::chunk::DataChunk; use crate::chunkid::ChunkId; -use crate::chunkmeta::ChunkMeta; use std::path::{Path, PathBuf}; /// Store chunks, with metadata, persistently. @@ -43,23 +42,26 @@ impl Store { } /// Save a chunk into a store. - pub fn save(&self, id: &ChunkId, meta: &ChunkMeta, chunk: &DataChunk) -> StoreResult<()> { + pub fn save(&self, id: &ChunkId, chunk: &DataChunk) -> StoreResult<()> { let (dir, metaname, dataname) = &self.filenames(id); if !dir.exists() { std::fs::create_dir_all(dir)?; } - std::fs::write(&metaname, meta.to_json())?; + std::fs::write(&metaname, chunk.meta().to_json())?; std::fs::write(&dataname, chunk.data())?; Ok(()) } /// Load a chunk from a store. pub fn load(&self, id: &ChunkId) -> StoreResult<DataChunk> { - let (_, _, dataname) = &self.filenames(id); + let (_, metaname, dataname) = &self.filenames(id); + let meta = std::fs::read(&metaname)?; + let meta = serde_json::from_slice(&meta)?; + let data = std::fs::read(&dataname)?; - let data = DataChunk::new(data); + let data = DataChunk::new(data, meta); Ok(data) } |