Skip to content

Commit

Permalink
Apply zstd compression
Browse files Browse the repository at this point in the history
  • Loading branch information
crumblingstatue committed Oct 2, 2021
1 parent d7e61aa commit 3be0dde
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 2 deletions.
42 changes: 42 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ fnv = "1.0.7"
directories = "4.0.1"
rfd = "0.5.0"
open = "2.0.1"
zstd = "0.9.0"

[dependencies.sfml]
git = "https://github.com/jeremyletang/rust-sfml.git"
Expand Down
7 changes: 5 additions & 2 deletions src/serialization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use serde::{Deserialize, Serialize};
pub fn read<T: for<'de> Deserialize<'de>>(mut source: impl Read) -> anyhow::Result<T> {
let mut ver = [0];
source.read_exact(&mut ver)?;
Ok(from_read(source)?)
Ok(from_read(zstd::Decoder::new(source)?)?)
}

pub fn read_from_file<T: for<'de> Deserialize<'de>>(path: impl AsRef<Path>) -> anyhow::Result<T> {
Expand All @@ -28,5 +28,8 @@ pub fn write_to_file<T: Serialize>(obj: &T, path: impl AsRef<Path>) -> anyhow::R

pub fn write<T: Serialize>(obj: &T, mut sink: impl Write) -> anyhow::Result<()> {
sink.write_all(&[DUMMY_VERSION])?;
Ok(write_named(&mut sink, obj)?)
let mut zstd = zstd::Encoder::new(sink, 0)?;
write_named(&mut zstd, obj)?;
zstd.finish()?;
Ok(())
}

0 comments on commit 3be0dde

Please sign in to comment.