(dictionary_path: String, source_files: Vec<String>)
| 224 | generate_compression_dictionary(&dictionary_path, &source_files)?; |
| 225 | |
| 226 | let mut total_size = 0; |
| 227 | let tmp_dir = env::temp_dir(); |
| 228 | |
| 229 | for filename in source_files { |
| 230 | info!("Compressing {}...", filename); |
| 231 | |
| 232 | let tmp_filename = tmp_dir |
| 233 | .join(uuid::Uuid::new_v4().to_string()) |
| 234 | .to_string_lossy() |
| 235 | .to_string(); |
| 236 | |
| 237 | fs::copy(&filename, &tmp_filename)?; |
| 238 | |
| 239 | let uncompressed_file_size = PathBuf::from(&filename).metadata()?.len() as u32; |
| 240 | |
| 241 | let output = Command::new("zstd") |
| 242 | .args([ |
| 243 | "--ultra", |
| 244 | "-22", |
| 245 | "-f", |
| 246 | "-D", |
| 247 | &dictionary_path, |
| 248 | &tmp_filename, |
| 249 | "-o", |
| 250 | &filename, |
| 251 | ]) |
| 252 | .output()?; |
| 253 | |
| 254 | if !output.status.success() { |
| 255 | return Err(io::Error::other("Failed to compress file")); |
| 256 | } |
| 257 | |
| 258 | let bytes = fs::read(&filename)?; |
| 259 | let compressed = add_bytecode_header(bytes, Some(uncompressed_file_size)); |
| 260 | fs::write(&filename, compressed)?; |
| 261 | |
| 262 | let compressed_file_size = PathBuf::from(&filename).metadata().unwrap().len() as usize; |
| 263 | |
| 264 | total_size += compressed_file_size; |
| 265 | } |
| 266 | |
| 267 | Ok(total_size) |
| 268 | } |
| 269 | |
| 270 | fn generate_compression_dictionary( |
| 271 | dictionary_path: &str, |
| 272 | source_files: &[String], |
| 273 | ) -> Result<(), io::Error> { |
| 274 | info!("Generating compression dictionary..."); |
no test coverage detected