From 3d552014c236f4d3c24ea1adb9e020d183148efb Mon Sep 17 00:00:00 2001 From: HouXiaoxuan Date: Tue, 19 Dec 2023 22:22:05 +0800 Subject: [PATCH] load&save for Blob --- src/models/blob.rs | 22 +++++++++++++++++++--- src/store.rs | 1 - 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/models/blob.rs b/src/models/blob.rs index 14dc96a..c3fc7fc 100644 --- a/src/models/blob.rs +++ b/src/models/blob.rs @@ -1,7 +1,8 @@ +use crate::models::object::Hash; +use crate::store::Store; +use crate::utils::util::calc_hash; use std::fs; use std::path::Path; -use crate::models::object::Hash; -use crate::utils::util::calc_hash; /** Blob @@ -19,7 +20,22 @@ impl Blob { let hash = calc_hash(&data); Blob { hash, data } } + + pub fn load(hash: &String) -> Blob { + let s = Store::new(); + let data = s.load(hash); + Blob { + hash: hash.clone(), + data, + } + } + + pub fn save(&self) { + let s = Store::new(); + s.save(&self.data); + } + pub fn get_hash(&self) -> String { self.hash.clone() } -} \ No newline at end of file +} diff --git a/src/store.rs b/src/store.rs index ed53d59..a0c4e66 100644 --- a/src/store.rs +++ b/src/store.rs @@ -41,7 +41,6 @@ impl Store { } #[cfg(test)] mod tests { - use crate::commands::init; use super::*;