aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authortslil <tslil@posteo.de>2026-07-13 21:28:31 +0100
committertslil <tslil@posteo.de>2026-07-14 08:55:10 +0100
commit861fb134ad6d77faeb23e9571a31e0c6031d7374 (patch)
tree48964e96e5db5b0a8854cb55bc2c3ed95aea4911 /src
parent3f289981bd9c8e800a6cd310d4b1f2f36634c9f1 (diff)
adding compression
Diffstat (limited to 'src')
-rw-r--r--src/state.rs10
1 files changed, 7 insertions, 3 deletions
diff --git a/src/state.rs b/src/state.rs
index a04412f..425e5d7 100644
--- a/src/state.rs
+++ b/src/state.rs
@@ -3,11 +3,12 @@ use directories::ProjectDirs;
use expanduser::expanduser;
use serde::{Deserialize, Serialize};
use walkdir::WalkDir;
+use zstd;
use crate::{config::Config, learner::Learner, trajectory::Trajectory};
fn default_state_path() -> String {
- let name = "mood.bin";
+ let name = "mood.bin.zstd";
ProjectDirs::from("qualifier", "organisation", "mood")
.and_then(|pd| pd.config_dir().join(name).to_str().map(|x| x.to_string()))
.unwrap_or(format!("~/.config/mood/{name}"))
@@ -57,7 +58,8 @@ impl State {
expanduser(default_state_path())
.map_err(|e| e.to_string())
.and_then(|p| fs::read(p).map_err(|e| e.to_string()))
- .and_then(|contents| bincode::deserialize(&contents).map_err(|e| e.to_string()))
+ .and_then(|contents| zstd::decode_all(&contents[..]).map_err(|e| e.to_string()))
+ .and_then(|decompressed| bincode::deserialize(&decompressed).map_err(|e| e.to_string()))
}
pub fn try_save(&self) -> Result<(), String> {
@@ -66,7 +68,9 @@ impl State {
_ = path.parent().map(std::fs::create_dir_all);
let serialised =
bincode::serialize(self).map_err(|e| format!("Failed to serialize state: {}", e))?;
- fs::write(&path, serialised)
+ let compressed = zstd::encode_all(serialised.as_slice(), 3)
+ .map_err(|e| format!("Failed to compress state: {}", e))?;
+ fs::write(&path, compressed)
.map_err(|e| format!("Failed to write state file at {}: {}", str_path, e))?;
Ok(())
}