diff options
author | Lars Wirzenius <liw@liw.fi> | 2021-05-24 08:55:14 +0300 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2021-05-29 11:41:15 +0300 |
commit | 6de230c382a4329df00bc11cc1ffb90390b13159 (patch) | |
tree | d4f0668be0d5cd07ea32af2b0978696658532122 /src/chunker.rs | |
parent | 566dd94d2e46c489b50d84a1fd24683460e5cfdc (diff) | |
download | obnam2-6de230c382a4329df00bc11cc1ffb90390b13159.tar.gz |
refactor: make metadata be part of datachunk
This makes it harder to lose the metadata for a chunk, or to use
unrelated metadata and chunk. Also, soon I will refactor things for
encrypting chunks, which will need metadata embedded in the encrypted
chunk.
Sponsored-by: author
Diffstat (limited to 'src/chunker.rs')
-rw-r--r-- | src/chunker.rs | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/src/chunker.rs b/src/chunker.rs index eeeed8d..a7a39f1 100644 --- a/src/chunker.rs +++ b/src/chunker.rs @@ -31,7 +31,7 @@ impl Chunker { } } - pub fn read_chunk(&mut self) -> ChunkerResult<Option<(ChunkMeta, DataChunk)>> { + pub fn read_chunk(&mut self) -> ChunkerResult<Option<DataChunk>> { let mut used = 0; loop { @@ -52,18 +52,18 @@ impl Chunker { let buffer = &self.buf.as_slice()[..used]; let hash = sha256(buffer); let meta = ChunkMeta::new(&hash); - let chunk = DataChunk::new(buffer.to_vec()); - Ok(Some((meta, chunk))) + let chunk = DataChunk::new(buffer.to_vec(), meta); + Ok(Some(chunk)) } } impl Iterator for Chunker { - type Item = ChunkerResult<(ChunkMeta, DataChunk)>; + type Item = ChunkerResult<DataChunk>; - fn next(&mut self) -> Option<ChunkerResult<(ChunkMeta, DataChunk)>> { + fn next(&mut self) -> Option<ChunkerResult<DataChunk>> { match self.read_chunk() { Ok(None) => None, - Ok(Some((meta, chunk))) => Some(Ok((meta, chunk))), + Ok(Some(chunk)) => Some(Ok(chunk)), Err(e) => Some(Err(e)), } } |