diff --git a/repak/src/pak.rs b/repak/src/pak.rs index 71b3973..55bff0b 100644 --- a/repak/src/pak.rs +++ b/repak/src/pak.rs @@ -89,7 +89,7 @@ pub struct PakWriter { } pub struct ParallelPakWriter { - tx: std::sync::mpsc::SyncSender<(String, Arc>)>, + tx: std::sync::mpsc::SyncSender<(String, bool, Arc>)>, } #[derive(Debug)] @@ -273,14 +273,23 @@ impl PakWriter { self.writer } - pub fn write_file(&mut self, path: &str, data: impl AsRef<[u8]>) -> Result<(), super::Error> { + pub fn write_file( + &mut self, + path: &str, + allow_compress: bool, + data: impl AsRef<[u8]>, + ) -> Result<(), super::Error> { self.pak.index.add_entry( path, Entry::write_file( &mut self.writer, self.pak.version, &mut self.pak.compression, - &self.allowed_compression, + if allow_compress { + &self.allowed_compression + } else { + &[] + }, data.as_ref(), )?, ); @@ -308,9 +317,13 @@ impl PakWriter { .into_iter() .parallel_map_scoped( scope, - |(path, data): (String, Arc>)| -> Result<_, Error> { - let partial_entry = - build_partial_entry(&self.allowed_compression, &data)?; + |(path, allow_compress, data): (String, bool, Arc>)| -> Result<_, Error> { + let allowed_compression = if allow_compress { + self.allowed_compression.as_slice() + } else { + &[] + }; + let partial_entry = build_partial_entry(allowed_compression, &data)?; let data = partial_entry.blocks.is_empty().then(|| Arc::new(data)); Ok((path, data, partial_entry)) }, @@ -363,8 +376,8 @@ impl PakWriter { } impl ParallelPakWriter { - pub fn write_file(&mut self, path: String, data: Vec) -> Result<(), Error> { - self.tx.send((path, Arc::new(data))).unwrap(); + pub fn write_file(&mut self, path: String, compress: bool, data: Vec) -> Result<(), Error> { + self.tx.send((path, compress, Arc::new(data))).unwrap(); Ok(()) } } diff --git a/repak/tests/test.rs b/repak/tests/test.rs index 5c63f8c..e951c02 100644 --- a/repak/tests/test.rs +++ b/repak/tests/test.rs @@ -185,7 +185,7 @@ fn test_write(_version: repak::Version, _file_name: &str, bytes: &[u8]) { for path in pak_reader.files() { let data = pak_reader.get(&path, &mut reader).unwrap(); - pak_writer.write_file(&path, data).unwrap(); + pak_writer.write_file(&path, false, data).unwrap(); } assert!(pak_writer.write_index().unwrap().into_inner() == reader.into_inner()); diff --git a/repak_cli/src/main.rs b/repak_cli/src/main.rs index b2ae887..e042868 100644 --- a/repak_cli/src/main.rs +++ b/repak_cli/src/main.rs @@ -508,7 +508,7 @@ fn pack(args: ActionPack) -> Result<(), repak::Error> { if args.verbose { log.println(format!("packing {}", &rel)); } - writer.write_file(rel.to_string(), std::fs::read(p)?)?; + writer.write_file(rel.to_string(), true, std::fs::read(p)?)?; } Ok(()) })?;