MCPcopy Create free account
hub / github.com/awslabs/llrt / compress_bytecode

Function compress_bytecode

llrt_core/build.rs:226–271  ·  view source on GitHub ↗
(dictionary_path: String, source_files: Vec<String>)

Source from the content-addressed store, hash-verified

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
270fn generate_compression_dictionary(
271 dictionary_path: &str,
272 source_files: &[String],
273) -> Result<(), io::Error> {
274 info!("Generating compression dictionary...");

Callers 1

generate_bytecode_cacheFunction · 0.85

Calls 9

copyFunction · 0.85
fromFunction · 0.85
add_bytecode_headerFunction · 0.85
joinMethod · 0.80
readFunction · 0.50
writeFunction · 0.50
to_stringMethod · 0.45
lenMethod · 0.45

Tested by

no test coverage detected