mirror of
https://github.com/exoticorn/microw8.git
synced 2026-01-20 11:16:42 +01:00
print fractional compressed size
This commit is contained in:
@@ -27,4 +27,4 @@ webbrowser = { version = "0.6.0", optional = true }
|
|||||||
ansi_term = "0.12.1"
|
ansi_term = "0.12.1"
|
||||||
cpal = { version = "0.13.5", optional = true }
|
cpal = { version = "0.13.5", optional = true }
|
||||||
rubato = { version = "0.11.0", optional = true }
|
rubato = { version = "0.11.0", optional = true }
|
||||||
winapi = { version = "0.3.9", features = ["timeapi"], optional = true }
|
winapi = { version = "0.3.9", features = ["timeapi"], optional = true }
|
||||||
|
|||||||
@@ -164,7 +164,10 @@ fn load_cart(filename: &Path, config: &Config) -> (Result<Vec<u8>>, Vec<PathBuf>
|
|||||||
|
|
||||||
if let Some(ref pack_config) = config.pack {
|
if let Some(ref pack_config) = config.pack {
|
||||||
cart = uw8_tool::pack(&cart, pack_config)?;
|
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 {
|
if let Some(ref path) = config.output_path {
|
||||||
|
|||||||
2
uw8-tool/Cargo.lock
generated
2
uw8-tool/Cargo.lock
generated
@@ -189,7 +189,7 @@ checksum = "8ccb82d61f80a663efe1f787a51b16b5a51e3314d6ac365b08639f52387b33f3"
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "upkr"
|
name = "upkr"
|
||||||
version = "0.1.0"
|
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 = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"cdivsufsort",
|
"cdivsufsort",
|
||||||
|
|||||||
@@ -11,5 +11,5 @@ wasm-encoder = "0.8"
|
|||||||
walrus = "0.19"
|
walrus = "0.19"
|
||||||
anyhow = "1"
|
anyhow = "1"
|
||||||
pico-args = "0.4"
|
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"
|
pbr = "1"
|
||||||
@@ -286,7 +286,7 @@ impl BaseModule {
|
|||||||
|
|
||||||
pub fn create_binary(path: &Path) -> Result<()> {
|
pub fn create_binary(path: &Path) -> Result<()> {
|
||||||
let base1 = BaseModule::for_format_version(1)?.to_wasm();
|
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)?;
|
File::create(path)?.write_all(&data)?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,15 @@
|
|||||||
mod base_module;
|
mod base_module;
|
||||||
mod pack;
|
|
||||||
mod filter_exports;
|
mod filter_exports;
|
||||||
|
mod pack;
|
||||||
|
|
||||||
pub use base_module::BaseModule;
|
pub use base_module::BaseModule;
|
||||||
pub use pack::{pack, pack_file, unpack, unpack_file, PackConfig};
|
|
||||||
pub use filter_exports::filter_exports;
|
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.
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -63,6 +63,7 @@ pub fn pack(data: &[u8], config: &PackConfig) -> Result<Vec<u8>> {
|
|||||||
uw8.extend_from_slice(&upkr::pack(
|
uw8.extend_from_slice(&upkr::pack(
|
||||||
&result[8..],
|
&result[8..],
|
||||||
level,
|
level,
|
||||||
|
false,
|
||||||
Some(&mut |pos| {
|
Some(&mut |pos| {
|
||||||
pb.set(pos as u64);
|
pb.set(pos as u64);
|
||||||
}),
|
}),
|
||||||
@@ -89,7 +90,7 @@ pub fn unpack(data: Vec<u8>) -> Result<Vec<u8>> {
|
|||||||
let (version, data) = match data[0] {
|
let (version, data) = match data[0] {
|
||||||
0 => return Ok(data),
|
0 => return Ok(data),
|
||||||
1 => (1, data[1..].to_vec()),
|
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),
|
other => bail!("Uknown format version {}", other),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user