implement upkr unpacker in wasm, use to load compressed base

This commit is contained in:
2021-11-20 23:36:16 +01:00
parent f7e3202c39
commit 93b2bb60bd
6 changed files with 149 additions and 19 deletions

View File

@@ -192,6 +192,13 @@ impl BaseModule {
File::create(path)?.write_all(&self.to_wasm())?;
Ok(())
}
pub fn create_binary(path: &Path) -> Result<()> {
let base1 = BaseModule::for_format_version(1)?.to_wasm();
let data = upkr::pack(&base1);
File::create(path)?.write_all(&data)?;
Ok(())
}
}
fn add_function(

5
uw8-tool/src/lib.rs Normal file
View File

@@ -0,0 +1,5 @@
mod base_module;
pub mod pack;
pub use base_module::BaseModule;
pub use pack::{pack_file, unpack, unpack_file};

View File

@@ -1,10 +1,7 @@
mod base_module;
mod pack;
use std::path::PathBuf;
use anyhow::Result;
use base_module::BaseModule;
use uw8_tool::BaseModule;
use pico_args::Arguments;
fn main() -> Result<()> {
@@ -13,20 +10,19 @@ fn main() -> Result<()> {
if let Some(cmd) = args.subcommand()? {
match cmd.as_str() {
"make-base" => {
let version: u8 = args.free_from_str()?;
BaseModule::for_format_version(version)?
.write_to_file(format!("base{}.wasm", version))?;
let path: PathBuf = args.free_from_str()?;
BaseModule::create_binary(&path)?;
}
"pack" => {
let version: u8 = args.opt_value_from_str(["-v", "--version"])?.unwrap_or(1);
let source: PathBuf = args.free_from_str()?;
let dest: PathBuf = args.free_from_str()?;
pack::pack_file(&source, &dest, version)?;
uw8_tool::pack_file(&source, &dest, version)?;
}
"unpack" => {
let source: PathBuf = args.free_from_str()?;
let dest: PathBuf = args.free_from_str()?;
pack::unpack_file(&source, &dest)?;
uw8_tool::unpack_file(&source, &dest)?;
}
_ => {
eprintln!("Unknown subcommand '{}'", cmd);