Skip to content

Commit

Permalink
fix: decompressing gzip is now a result, percent fix
Browse files Browse the repository at this point in the history
  • Loading branch information
simbleau committed Oct 16, 2023
1 parent 8cd7d8f commit 3139417
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ members = ["demo"]

[workspace.package]
edition = "2021"
version = "0.3.5"
version = "0.3.6"
license = "MIT OR Apache-2.0"
repository = "https://github.com/vectorgameexperts/bevy-vello"

Expand Down
2 changes: 1 addition & 1 deletion src/assets/asset_loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ impl AssetLoader for VelloVectorLoader {
if gzipped {
debug!("decompressing {}...", path.display());
// Decompress
let decrompressed_bytes = compression::decompress_gzip(&bytes);
let decrompressed_bytes = compression::decompress_gzip(&bytes)?;
let path_without_gz = path.with_extension("");
bytes = decrompressed_bytes.into_bytes();
// Remove .gz extension
Expand Down
9 changes: 5 additions & 4 deletions src/compression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,24 @@ use bevy::log;
use std::io::Read;

/// Deflate gzip compression to plaintext
pub fn decompress_gzip(content: &[u8]) -> String {
pub fn decompress_gzip(content: &[u8]) -> Result<String, bevy::asset::Error> {
#[cfg(debug_assertions)]
{
log::info!("original (gzipped) size: {} bytes", content.len());
}
let mut d = flate2::read::GzDecoder::new(content);
let mut s = String::new();
d.read_to_string(&mut s).unwrap();
d.read_to_string(&mut s)
.map_err(|e| bevy::asset::Error::from(e))?;
#[cfg(debug_assertions)]
{
let new_bytes = s.as_bytes();
let after_percent = new_bytes.len() as f32 / content.len() as f32;
let after_percent = (new_bytes.len() as f64 / content.len() as f64) * 100.0;
log::info!(
"decompressed size: {} bytes ({:.2}%)",
new_bytes.len(),
after_percent
);
}
s
Ok(s)
}

0 comments on commit 3139417

Please sign in to comment.