diff --git a/examples/rando_p.pak b/examples/rando_p.pak deleted file mode 100644 index e63d229..0000000 Binary files a/examples/rando_p.pak and /dev/null differ diff --git a/examples/subcommands/unpack.rs b/examples/subcommands/unpack.rs index 61baf55..61d3526 100644 --- a/examples/subcommands/unpack.rs +++ b/examples/subcommands/unpack.rs @@ -6,12 +6,22 @@ pub fn unpack(path: String, key: String) -> Result<(), unpak::Error> { .unwrap_or_default(), ); let mut pak = super::load_pak(path.clone(), key)?; - for file in pak.files() { - std::fs::create_dir_all(folder.join(&file).parent().expect("will be a file"))?; - match pak.get(&file).expect("file should be in pak") { - Ok(data) => std::fs::write(folder.join(&file), data)?, - Err(e) => eprintln!("{e}"), + std::thread::scope(|scope| -> Result<(), unpak::Error> { + for file in pak.files() { + match pak.get(&file).expect("file should be in pak") { + Ok(data) => { + scope.spawn(move || -> Result<(), unpak::Error> { + std::fs::create_dir_all( + folder.join(&file).parent().expect("will be a file"), + )?; + println!("{file}"); + std::fs::write(folder.join(&file), data)?; + Ok(()) + }); + } + Err(e) => eprintln!("{e}"), + } } - } - Ok(()) + Ok(()) + }) } diff --git a/examples/unpak.rs b/examples/unpak.rs index 484d0bc..e9bc46c 100644 --- a/examples/unpak.rs +++ b/examples/unpak.rs @@ -7,14 +7,13 @@ fn main() { help() }; // can't map key to &[u8] because refers to owned data - match match args.next().unwrap_or_default().as_str() { + if let Err(e) = match args.next().unwrap_or_default().as_str() { "version" => subcommands::version(path, args.next().unwrap_or_default()), "list" => subcommands::list(path, args.next().unwrap_or_default()), "unpack" | "" => subcommands::unpack(path, args.next().unwrap_or_default()), "help" | _ => help(), } { - Ok(_) => println!("success!"), - Err(e) => eprintln!("{e}"), + eprintln!("{e}") } } diff --git a/src/entry.rs b/src/entry.rs index 9f34865..86f2371 100644 --- a/src/entry.rs +++ b/src/entry.rs @@ -98,7 +98,10 @@ impl Entry { io::copy( &mut <$decompressor>::new( &data[match version >= Version::RelativeChunkOffsets { - true => block.start as usize..block.end as usize, + true => { + (block.start - (data_offset - self.offset)) as usize + ..(block.end - (data_offset - self.offset)) as usize + } false => { (block.start - data_offset) as usize ..(block.end - data_offset) as usize