print fractional compressed size

This commit is contained in:
2022-06-22 00:16:35 +02:00
parent 1f6de62e5d
commit 7caad08b7c
7 changed files with 20 additions and 8 deletions

View File

@@ -164,7 +164,10 @@ fn load_cart(filename: &Path, config: &Config) -> (Result<Vec<u8>>, Vec<PathBuf>
if let Some(ref pack_config) = config.pack {
cart = uw8_tool::pack(&cart, pack_config)?;
println!("packed size: {} bytes", cart.len());
println!(
"\npacked size: {:.2} bytes",
uw8_tool::compressed_size(&cart)
);
}
if let Some(ref path) = config.output_path {

2
uw8-tool/Cargo.lock generated
View File

@@ -189,7 +189,7 @@ checksum = "8ccb82d61f80a663efe1f787a51b16b5a51e3314d6ac365b08639f52387b33f3"
[[package]]
name = "upkr"
version = "0.1.0"
source = "git+https://github.com/exoticorn/upkr.git?rev=2e7983fc#2e7983fc650788d98da2eecef2d16f63e849e4a0"
source = "git+https://github.com/exoticorn/upkr.git?rev=d93aec186c9fb91d962c488682a2db125c61306c#d93aec186c9fb91d962c488682a2db125c61306c"
dependencies = [
"anyhow",
"cdivsufsort",

View File

@@ -11,5 +11,5 @@ wasm-encoder = "0.8"
walrus = "0.19"
anyhow = "1"
pico-args = "0.4"
upkr = { git = "https://github.com/exoticorn/upkr.git", rev = "2e7983fc" }
upkr = { git = "https://github.com/exoticorn/upkr.git", rev = "d93aec186c9fb91d962c488682a2db125c61306c" }
pbr = "1"

View File

@@ -286,7 +286,7 @@ impl BaseModule {
pub fn create_binary(path: &Path) -> Result<()> {
let base1 = BaseModule::for_format_version(1)?.to_wasm();
let data = upkr::pack(&base1, 4, None);
let data = upkr::pack(&base1, 4, false, None);
File::create(path)?.write_all(&data)?;
Ok(())
}

View File

@@ -1,7 +1,15 @@
mod base_module;
mod pack;
mod filter_exports;
mod pack;
pub use base_module::BaseModule;
pub use pack::{pack, pack_file, unpack, unpack_file, PackConfig};
pub use filter_exports::filter_exports;
pub use pack::{pack, pack_file, unpack, unpack_file, PackConfig};
pub fn compressed_size(cart: &[u8]) -> f32 {
if cart[0] != 2 {
cart.len() as f32
} else {
upkr::compressed_size(&cart[1..]) + 1.
}
}

View File

@@ -63,6 +63,7 @@ pub fn pack(data: &[u8], config: &PackConfig) -> Result<Vec<u8>> {
uw8.extend_from_slice(&upkr::pack(
&result[8..],
level,
false,
Some(&mut |pos| {
pb.set(pos as u64);
}),
@@ -89,7 +90,7 @@ pub fn unpack(data: Vec<u8>) -> Result<Vec<u8>> {
let (version, data) = match data[0] {
0 => return Ok(data),
1 => (1, data[1..].to_vec()),
2 => (1, upkr::unpack(&data[1..])),
2 => (1, upkr::unpack(&data[1..], false)),
other => bail!("Uknown format version {}", other),
};