aboutsummaryrefslogtreecommitdiff
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
parent3f289981bd9c8e800a6cd310d4b1f2f36634c9f1 (diff)
adding compression
-rw-r--r--Cargo.lock47
-rw-r--r--Cargo.toml1
-rw-r--r--src/state.rs10
3 files changed, 55 insertions, 3 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 6e73af8..341d40b 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -68,6 +68,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e17dd265a7d0f31ef544e1b20e03add05d3b45b491b633b10d67145d2acc1a38"
dependencies = [
"find-msvc-tools",
+ "jobserver",
+ "libc",
"shlex",
]
@@ -266,6 +268,16 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8f42a60cbdf9a97f5d2305f08a87dc4e09308d1276d28c869c684d7777685682"
[[package]]
+name = "jobserver"
+version = "0.1.35"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "1c00acbd29eabad4a2392fa0e921c874934dbbf4194312ad20f04a0ed67a3cb3"
+dependencies = [
+ "getrandom 0.4.3",
+ "libc",
+]
+
+[[package]]
name = "js-sys"
version = "0.3.103"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -321,6 +333,7 @@ dependencies = [
"serde",
"serde_json",
"walkdir",
+ "zstd",
]
[[package]]
@@ -351,6 +364,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a89322df9ebe1c1578d689c92318e070967d1042b512afbe49518723f4e6d5cd"
[[package]]
+name = "pkg-config"
+version = "0.3.33"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "19f132c84eca552bf34cab8ec81f1c1dcc229b811638f9d283dceabe58c5569e"
+
+[[package]]
name = "proc-macro2"
version = "1.0.106"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -739,3 +758,31 @@ name = "zmij"
version = "1.0.23"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "29666d0abbfad1e3dc4dcf6144730dd3a3ab225bbbdac83319345b1b44ccfc1b"
+
+[[package]]
+name = "zstd"
+version = "0.13.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "e91ee311a569c327171651566e07972200e76fcfe2242a4fa446149a3881c08a"
+dependencies = [
+ "zstd-safe",
+]
+
+[[package]]
+name = "zstd-safe"
+version = "7.2.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "8f49c4d5f0abb602a93fb8736af2a4f4dd9512e36f7f570d66e65ff867ed3b9d"
+dependencies = [
+ "zstd-sys",
+]
+
+[[package]]
+name = "zstd-sys"
+version = "2.0.16+zstd.1.5.7"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "91e19ebc2adc8f83e43039e79776e3fda8ca919132d68a1fed6a5faca2683748"
+dependencies = [
+ "cc",
+ "pkg-config",
+]
diff --git a/Cargo.toml b/Cargo.toml
index 0b3052f..4353904 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -13,6 +13,7 @@ rand = "0.10.2"
serde = {version = "1.0.228", features = ["derive"] }
serde_json = "1.0.150"
walkdir = "2.5.0"
+zstd = "0.13.3"
[profile.release]
strip = true
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(())
}