From 9b9f39e81c00f420b2a9853bac3d6836364a208a Mon Sep 17 00:00:00 2001 From: Aria Date: Thu, 6 Mar 2025 01:26:28 +1100 Subject: [PATCH] V0.1 --- .gitignore | 1 + Cargo.lock | 444 ++++++++++++++++++++++++++++++++++++++++++++++++++++ Cargo.toml | 13 ++ src/main.rs | 378 ++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 836 insertions(+) create mode 100644 .gitignore create mode 100644 Cargo.lock create mode 100644 Cargo.toml create mode 100644 src/main.rs diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ea8c4bf --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/target diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 0000000..4ed7538 --- /dev/null +++ b/Cargo.lock @@ -0,0 +1,444 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 4 + +[[package]] +name = "anstream" +version = "0.6.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8acc5369981196006228e28809f761875c0327210a891e941f4c683b3a99529b" +dependencies = [ + "anstyle", + "anstyle-parse", + "anstyle-query", + "anstyle-wincon", + "colorchoice", + "is_terminal_polyfill", + "utf8parse", +] + +[[package]] +name = "anstyle" +version = "1.0.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "55cc3b69f167a1ef2e161439aa98aed94e6028e5f9a59be9a6ffb47aef1651f9" + +[[package]] +name = "anstyle-parse" +version = "0.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3b2d16507662817a6a20a9ea92df6652ee4f94f914589377d69f3b21bc5798a9" +dependencies = [ + "utf8parse", +] + +[[package]] +name = "anstyle-query" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "79947af37f4177cfead1110013d678905c37501914fba0efea834c3fe9a8d60c" +dependencies = [ + "windows-sys", +] + +[[package]] +name = "anstyle-wincon" +version = "3.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ca3534e77181a9cc07539ad51f2141fe32f6c3ffd4df76db8ad92346b003ae4e" +dependencies = [ + "anstyle", + "once_cell", + "windows-sys", +] + +[[package]] +name = "anyhow" +version = "1.0.97" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dcfed56ad506cb2c684a14971b8861fdc3baaaae314b9e5f9bb532cbe3ba7a4f" + +[[package]] +name = "bumpalo" +version = "3.17.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1628fb46dfa0b37568d12e5edd512553eccf6a22a78e8bde00bb4aed84d5bdbf" + +[[package]] +name = "bytesize" +version = "2.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a3c8f83209414aacf0eeae3cf730b18d6981697fba62f200fcfb92b9f082acba" + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "clap" +version = "4.5.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "027bb0d98429ae334a8698531da7077bdf906419543a35a55c2cb1b66437d767" +dependencies = [ + "clap_builder", + "clap_derive", +] + +[[package]] +name = "clap_builder" +version = "4.5.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5589e0cba072e0f3d23791efac0fd8627b49c829c196a492e88168e6a669d863" +dependencies = [ + "anstream", + "anstyle", + "clap_lex", + "strsim", +] + +[[package]] +name = "clap_derive" +version = "4.5.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bf4ced95c6f4a675af3da73304b9ac4ed991640c36374e4b46795c49e17cf1ed" +dependencies = [ + "heck", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "clap_lex" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f46ad14479a25103f283c0f10005961cf086d8dc42205bb44c46ac563475dca6" + +[[package]] +name = "colorchoice" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b63caa9aa9397e2d9480a9b13673856c78d8ac123288526c37d7839f2a86990" + +[[package]] +name = "compair" +version = "0.1.0" +dependencies = [ + "anyhow", + "bytesize", + "clap", + "indicatif", + "strum", + "strum_macros", + "temp-dir", +] + +[[package]] +name = "console" +version = "0.15.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "054ccb5b10f9f2cbf51eb355ca1d05c2d279ce1804688d0db74b4733a5aeafd8" +dependencies = [ + "encode_unicode", + "libc", + "once_cell", + "unicode-width", + "windows-sys", +] + +[[package]] +name = "encode_unicode" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34aa73646ffb006b8f5147f3dc182bd4bcb190227ce861fc4a4844bf8e3cb2c0" + +[[package]] +name = "heck" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" + +[[package]] +name = "indicatif" +version = "0.17.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "183b3088984b400f4cfac3620d5e076c84da5364016b4f49473de574b2586235" +dependencies = [ + "console", + "number_prefix", + "portable-atomic", + "unicode-width", + "web-time", +] + +[[package]] +name = "is_terminal_polyfill" +version = "1.70.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7943c866cc5cd64cbc25b2e01621d07fa8eb2a1a23160ee81ce38704e97b8ecf" + +[[package]] +name = "js-sys" +version = "0.3.77" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1cfaf33c695fc6e08064efbc1f72ec937429614f25eef83af942d0e227c3a28f" +dependencies = [ + "once_cell", + "wasm-bindgen", +] + +[[package]] +name = "libc" +version = "0.2.170" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "875b3680cb2f8f71bdcf9a30f38d48282f5d3c95cbf9b3fa57269bb5d5c06828" + +[[package]] +name = "log" +version = "0.4.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "30bde2b3dc3671ae49d8e2e9f044c7c005836e7a023ee57cffa25ab82764bb9e" + +[[package]] +name = "number_prefix" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "830b246a0e5f20af87141b25c173cd1b609bd7779a4617d6ec582abaf90870f3" + +[[package]] +name = "once_cell" +version = "1.20.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "945462a4b81e43c4e3ba96bd7b49d834c6f61198356aa858733bc4acf3cbe62e" + +[[package]] +name = "portable-atomic" +version = "1.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "350e9b48cbc6b0e028b0473b114454c6316e57336ee184ceab6e53f72c178b3e" + +[[package]] +name = "proc-macro2" +version = "1.0.94" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a31971752e70b8b2686d7e46ec17fb38dad4051d94024c88df49b667caea9c84" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.39" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c1f1914ce909e1658d9907913b4b91947430c7d9be598b15a1912935b8c04801" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "rustversion" +version = "1.0.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eded382c5f5f786b989652c49544c4877d9f015cc22e145a5ea8ea66c2921cd2" + +[[package]] +name = "strsim" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" + +[[package]] +name = "strum" +version = "0.27.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f64def088c51c9510a8579e3c5d67c65349dcf755e5479ad3d010aa6454e2c32" + +[[package]] +name = "strum_macros" +version = "0.27.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c77a8c5abcaf0f9ce05d62342b7d298c346515365c36b673df4ebe3ced01fde8" +dependencies = [ + "heck", + "proc-macro2", + "quote", + "rustversion", + "syn", +] + +[[package]] +name = "syn" +version = "2.0.99" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e02e925281e18ffd9d640e234264753c43edc62d64b2d4cf898f1bc5e75f3fc2" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "temp-dir" +version = "0.1.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bc1ee6eef34f12f765cb94725905c6312b6610ab2b0940889cfe58dae7bc3c72" + +[[package]] +name = "unicode-ident" +version = "1.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a5f39404a5da50712a4c1eecf25e90dd62b613502b7e925fd4e4d19b5c96512" + +[[package]] +name = "unicode-width" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fc81956842c57dac11422a97c3b8195a1ff727f06e85c84ed2e8aa277c9a0fd" + +[[package]] +name = "utf8parse" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821" + +[[package]] +name = "wasm-bindgen" +version = "0.2.100" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1edc8929d7499fc4e8f0be2262a241556cfc54a0bea223790e71446f2aab1ef5" +dependencies = [ + "cfg-if", + "once_cell", + "wasm-bindgen-macro", +] + +[[package]] +name = "wasm-bindgen-backend" +version = "0.2.100" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2f0a0651a5c2bc21487bde11ee802ccaf4c51935d0d3d42a6101f98161700bc6" +dependencies = [ + "bumpalo", + "log", + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.100" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7fe63fc6d09ed3792bd0897b314f53de8e16568c2b3f7982f468c0bf9bd0b407" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.100" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ae87ea40c9f689fc23f209965b6fb8a99ad69aeeb0231408be24920604395de" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-backend", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.100" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1a05d73b933a847d6cccdda8f838a22ff101ad9bf93e33684f39c1f5f0eece3d" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "web-time" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a6580f308b1fad9207618087a65c04e7a10bc77e02c8e84e9b00dd4b12fa0bb" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + +[[package]] +name = "windows-sys" +version = "0.59.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" +dependencies = [ + "windows-targets", +] + +[[package]] +name = "windows-targets" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" +dependencies = [ + "windows_aarch64_gnullvm", + "windows_aarch64_msvc", + "windows_i686_gnu", + "windows_i686_gnullvm", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" + +[[package]] +name = "windows_i686_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..675d221 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,13 @@ +[package] +name = "compair" +version = "0.1.0" +edition = "2021" + +[dependencies] +anyhow = "1.0.97" +bytesize = "2.0.1" +clap = { version = "4.5.31", features = ["derive"] } +indicatif = "0.17.11" +strum = "0.27.1" +strum_macros = "0.27.1" +temp-dir = "0.1.14" diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..d01bc55 --- /dev/null +++ b/src/main.rs @@ -0,0 +1,378 @@ +use anyhow::{Ok, Result}; +use bytesize::ByteSize; +use clap::Parser; +use indicatif::ProgressBar; +use std::process::Command; +use std::{ + collections::HashMap, + fs, + path::{Path, PathBuf}, + vec, +}; +use temp_dir::TempDir; + +use strum::IntoEnumIterator; +use strum_macros::EnumIter; + +#[derive(Parser, Debug)] +#[command(version, about, long_about = "This is a small tool I've made to make quickly comparing compression formats easier!\n\nUse `--lzma` to just test lzma or use multiple specifiers to just test them (`--lzma --bzip3`)\n\nThe commandline flags used to test are listed bellow.")] +struct Args { + /// Path of file for compression tests + #[arg()] + path: PathBuf, + + /// Test Bzip2 compression (--best -c) - Tested by default + #[arg(long)] + bzip2: bool, + + /// Test Bzip3 compression (-e -c) - Tested by default + #[arg(long)] + bzip3: bool, + + /// Test LZMA compression (-z -c -9) + #[arg(long)] + lzma: bool, + + /// Test LZMA compression (-z -c -9e) + #[arg(long)] + lzma_e: bool, + + /// Test ZSTD compression (-z -9 -T0 -c) + #[arg(long)] + zstd9: bool, + + /// Test ZSTD compression (-z -19 -T0 -c) - Tested by default + #[arg(long)] + zstd19: bool, + + /// Test ZSTD compression (-z --ultra -22 -T0 -c) + #[arg(long)] + zstd22: bool, + + /// Test all formats + #[arg(long, short)] + all: bool, +} + +#[derive(Parser, Debug, PartialEq, Eq, Hash, EnumIter)] +enum Formats { + LZMA, + LzmaE, + Bzip2, + Bzip3, + ZSTD9, + ZSTD19, + ZSTD22, +} + +fn main() -> Result<(), anyhow::Error> { + let args = Args::parse(); + + let mut tests = vec![Formats::Bzip2, Formats::Bzip3, Formats::ZSTD19]; + + if args.all { + tests = vec![]; + for format in Formats::iter() { + tests.push(format); + } + } else if args.bzip2 || args.bzip3 || args.lzma || args.lzma_e || args.zstd9 || args.zstd19 || args.zstd22 { + tests = vec![]; + + if args.bzip2 { + tests.push(Formats::Bzip2); + } + + if args.bzip3 { + tests.push(Formats::Bzip3); + } + + if args.lzma { + tests.push(Formats::LZMA); + } + + if args.lzma_e { + tests.push(Formats::LzmaE); + } + + if args.zstd9 { + tests.push(Formats::ZSTD9); + } + + if args.zstd19 { + tests.push(Formats::ZSTD19); + } + + if args.zstd22 { + tests.push(Formats::ZSTD22); + } + } + + let temp_dir = TempDir::new()?; + + let mut results: HashMap = HashMap::new(); + + let bar = ProgressBar::new(tests.len() as u64); + bar.tick(); + + for test in tests { + let file_size = match test { + Formats::LZMA => lzma_test(args.path.clone(), temp_dir.path())?, + Formats::Bzip2 => bzip2_test(args.path.clone(), temp_dir.path())?, + Formats::Bzip3 => bzip3_test(args.path.clone(), temp_dir.path())?, + Formats::ZSTD9 => zstd9_test(args.path.clone(), temp_dir.path())?, + Formats::ZSTD19 => zstd19_test(args.path.clone(), temp_dir.path())?, + Formats::ZSTD22 => zstd22_test(args.path.clone(), temp_dir.path())?, + Formats::LzmaE => lzma_e_test(args.path.clone(), temp_dir.path())?, + }; + + results.insert(test, file_size); + bar.inc(1); + } + bar.finish(); + + for (format, size) in results { + println!("{:?}: {}", format, ByteSize::b(size).display().si()) + } + + temp_dir.cleanup()?; + + Ok(()) +} + +fn bzip2_test(path: PathBuf, temp_dir: &Path) -> Result { + let _output = if cfg!(target_os = "windows") { + Command::new("cmd") + .arg("/C") + .arg(format!( + "bzip2 --best -c {} > {}/{}.bzip2", + path.display(), + temp_dir.display(), + path.file_name().unwrap().to_str().unwrap() + )) + .output() + .expect("failed to execute process") + } else { + Command::new("sh") + .arg("-c") + .arg(format!( + "bzip2 --best -c {} > {}/{}.bzip2", + path.display(), + temp_dir.display(), + path.file_name().unwrap().to_str().unwrap() + )) + .output() + .expect("failed to execute process") + }; + + let metadata = fs::metadata(format!( + "{}/{}.bzip2", + temp_dir.display(), + path.file_name().unwrap().to_str().unwrap() + ))?; + + Ok(metadata.len()) +} + +fn bzip3_test(path: PathBuf, temp_dir: &Path) -> Result { + let _output = if cfg!(target_os = "windows") { + Command::new("cmd") + .arg("/C") + .arg(format!( + "bzip3 -e -c {} > {}/{}.bzip3", + path.display(), + temp_dir.display(), + path.file_name().unwrap().to_str().unwrap() + )) + .output() + .expect("failed to execute process") + } else { + Command::new("sh") + .arg("-c") + .arg(format!( + "bzip3 -e -c {} > {}/{}.bzip3", + path.display(), + temp_dir.display(), + path.file_name().unwrap().to_str().unwrap() + )) + .output() + .expect("failed to execute process") + }; + + let metadata = fs::metadata(format!( + "{}/{}.bzip3", + temp_dir.display(), + path.file_name().unwrap().to_str().unwrap() + ))?; + + Ok(metadata.len()) +} + +fn zstd9_test(path: PathBuf, temp_dir: &Path) -> Result { + let _output = if cfg!(target_os = "windows") { + Command::new("cmd") + .arg("/C") + .arg(format!( + "zstd -z -9 -T0 -c {} > {}/{}-9.zstd", + path.display(), + temp_dir.display(), + path.file_name().unwrap().to_str().unwrap() + )) + .output() + .expect("failed to execute process") + } else { + Command::new("sh") + .arg("-c") + .arg(format!( + "zstd -z -9 -T0 -c {} > {}/{}-9.zstd", + path.display(), + temp_dir.display(), + path.file_name().unwrap().to_str().unwrap() + )) + .output() + .expect("failed to execute process") + }; + + let metadata = fs::metadata(format!( + "{}/{}-9.zstd", + temp_dir.display(), + path.file_name().unwrap().to_str().unwrap() + ))?; + + Ok(metadata.len()) +} + +fn zstd19_test(path: PathBuf, temp_dir: &Path) -> Result { + let _output = if cfg!(target_os = "windows") { + Command::new("cmd") + .arg("/C") + .arg(format!( + "zstd -z -19 -T0 -c {} > {}/{}-19.zstd", + path.display(), + temp_dir.display(), + path.file_name().unwrap().to_str().unwrap() + )) + .output() + .expect("failed to execute process") + } else { + Command::new("sh") + .arg("-c") + .arg(format!( + "zstd -z -19 -T0 -c {} > {}/{}-19.zstd", + path.display(), + temp_dir.display(), + path.file_name().unwrap().to_str().unwrap() + )) + .output() + .expect("failed to execute process") + }; + + let metadata = fs::metadata(format!( + "{}/{}-19.zstd", + temp_dir.display(), + path.file_name().unwrap().to_str().unwrap() + ))?; + + Ok(metadata.len()) +} + +fn zstd22_test(path: PathBuf, temp_dir: &Path) -> Result { + let _output = if cfg!(target_os = "windows") { + Command::new("cmd") + .arg("/C") + .arg(format!( + "zstd -z --ultra -22 -T0 -c {} > {}/{}-22.zstd", + path.display(), + temp_dir.display(), + path.file_name().unwrap().to_str().unwrap() + )) + .output() + .expect("failed to execute process") + } else { + Command::new("sh") + .arg("-c") + .arg(format!( + "zstd -z --ultra -22 -T0 -c {} > {}/{}-22.zstd", + path.display(), + temp_dir.display(), + path.file_name().unwrap().to_str().unwrap() + )) + .output() + .expect("failed to execute process") + }; + + let metadata = fs::metadata(format!( + "{}/{}-22.zstd", + temp_dir.display(), + path.file_name().unwrap().to_str().unwrap() + ))?; + + Ok(metadata.len()) +} + +fn lzma_test(path: PathBuf, temp_dir: &Path) -> Result { + let _output = if cfg!(target_os = "windows") { + Command::new("cmd") + .arg("/C") + .arg(format!( + "xz -z -c -9 {} > {}/{}.xz", + path.display(), + temp_dir.display(), + path.file_name().unwrap().to_str().unwrap() + )) + .output() + .expect("failed to execute process") + } else { + Command::new("sh") + .arg("-c") + .arg(format!( + "xz -z -c -9 {} > {}/{}.xz", + path.display(), + temp_dir.display(), + path.file_name().unwrap().to_str().unwrap() + )) + .output() + .expect("failed to execute process") + }; + + let metadata = fs::metadata(format!( + "{}/{}.xz", + temp_dir.display(), + path.file_name().unwrap().to_str().unwrap() + ))?; + + Ok(metadata.len()) +} + +fn lzma_e_test(path: PathBuf, temp_dir: &Path) -> Result { + let _output = if cfg!(target_os = "windows") { + Command::new("cmd") + .arg("/C") + .arg(format!( + "xz -z -c -9e {} > {}/{}.xz", + path.display(), + temp_dir.display(), + path.file_name().unwrap().to_str().unwrap() + )) + .output() + .expect("failed to execute process") + } else { + Command::new("sh") + .arg("-c") + .arg(format!( + "xz -z -c -9e {} > {}/{}.xz", + path.display(), + temp_dir.display(), + path.file_name().unwrap().to_str().unwrap() + )) + .output() + .expect("failed to execute process") + }; + + let metadata = fs::metadata(format!( + "{}/{}.xz", + temp_dir.display(), + path.file_name().unwrap().to_str().unwrap() + ))?; + + Ok(metadata.len()) +}