From c0400511eb63b36c6de45429bdc0f5f883e98a18 Mon Sep 17 00:00:00 2001 From: matt Date: Mon, 23 Jun 2025 17:26:17 -0500 Subject: [PATCH] Add comic book aliases Added .cbt, .cbz, .cb7, and .cbr aliases for .tar, .zip, .7z, and .rar, respectively. --- CHANGELOG.md | 1 + README.md | 4 +++- src/extension.rs | 18 +++++++++--------- tests/mime.rs | 7 +++++-- 4 files changed, 18 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e0f569f..30c1c58 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,6 +22,7 @@ Categories Used: ### New Features +- Add aliases for comic books :) - Merge folders in decompression [\#798](https://github.com/ouch-org/ouch/pull/798) ([tommady](https://github.com/tommady)) - Add `--no-smart-unpack` flag to decompression command to disable smart unpack [\#809](https://github.com/ouch-org/ouch/pull/809) ([talis-fb](https://github.com/talis-fb)) diff --git a/README.md b/README.md index ae34414..62cb978 100644 --- a/README.md +++ b/README.md @@ -125,7 +125,9 @@ Output: If you wish to exclude non-free code from your build, you can disable RAR support by building without the `unrar` feature. -`tar` aliases are also supported: `tgz`, `tbz`, `tbz2`, `tlz4`, `txz`, `tlzma`, `tsz`, `tzst`. +Comic book aliases: `cbt`, `cbz`, `cb7`, `cbr` +and `tar` aliases: `tgz`, `tbz`, `tbz2`, `tlz4`, `txz`, `tlzma`, `tsz`, `tzst` +are also supported. Formats can be chained: diff --git a/src/extension.rs b/src/extension.rs index 48be0cb..1a1b036 100644 --- a/src/extension.rs +++ b/src/extension.rs @@ -27,7 +27,7 @@ pub const SUPPORTED_EXTENSIONS: &[&str] = &[ "br", ]; -pub const SUPPORTED_ALIASES: &[&str] = &["tgz", "tbz", "tlz4", "txz", "tzlma", "tsz", "tzst"]; +pub const SUPPORTED_ALIASES: &[&str] = &["tgz", "tbz", "tlz4", "txz", "tzlma", "tsz", "tzst", "cbt", "cbz", "cb7", "cbr", ]; #[cfg(not(feature = "unrar"))] pub const PRETTY_SUPPORTED_EXTENSIONS: &str = "tar, zip, bz, bz2, bz3, gz, lz4, xz, lzma, sz, zst, 7z"; @@ -89,16 +89,16 @@ pub enum CompressionFormat { Lzma, /// .sz Snappy, - /// tar, tgz, tbz, tbz2, tbz3, txz, tlz4, tlzma, tsz, tzst + /// tar, tgz, tbz, tbz2, tbz3, txz, tlz4, tlzma, tsz, tzst, cbt Tar, /// .zst Zstd, - /// .zip + /// .zip, .cbz Zip, // even if built without RAR support, we still want to recognise the format - /// .rar + /// .rar, .cbr Rar, - /// .7z + /// .7z, .cb7 SevenZip, /// .br Brotli, @@ -125,7 +125,7 @@ impl CompressionFormat { fn to_extension(ext: &[u8]) -> Option { Some(Extension::new( match ext { - b"tar" => &[Tar], + b"tar" | b"cbt" => &[Tar], b"tgz" => &[Tar, Gzip], b"tbz" | b"tbz2" => &[Tar, Bzip], b"tbz3" => &[Tar, Bzip3], @@ -133,7 +133,7 @@ fn to_extension(ext: &[u8]) -> Option { b"txz" | b"tlzma" => &[Tar, Lzma], b"tsz" => &[Tar, Snappy], b"tzst" => &[Tar, Zstd], - b"zip" => &[Zip], + b"zip" | b"cbz" => &[Zip], b"bz" | b"bz2" => &[Bzip], b"bz3" => &[Bzip3], b"gz" => &[Gzip], @@ -141,8 +141,8 @@ fn to_extension(ext: &[u8]) -> Option { b"xz" | b"lzma" => &[Lzma], b"sz" => &[Snappy], b"zst" => &[Zstd], - b"rar" => &[Rar], - b"7z" => &[SevenZip], + b"rar" | b"cbr" => &[Rar], + b"7z" | b"cb7" => &[SevenZip], b"br" => &[Brotli], _ => return None, }, diff --git a/tests/mime.rs b/tests/mime.rs index bf52179..6cd268c 100644 --- a/tests/mime.rs +++ b/tests/mime.rs @@ -17,13 +17,16 @@ fn sanity_check_through_mime() { write_random_content(test_file, &mut SmallRng::from_entropy()); let formats = [ - "7z", "tar", "zip", "tar.gz", "tgz", "tbz", "tbz2", "txz", "tlzma", "tzst", "tar.bz", "tar.bz2", "tar.lzma", - "tar.xz", "tar.zst", + "7z", "cb7", "tar", "cbt", "zip", "cbz", "tar.gz", "tgz", "tbz", "tbz2", "txz", "tlzma", "tzst", + "tar.bz", "tar.bz2", "tar.lzma", "tar.xz", "tar.zst", ]; let expected_mimes = [ + "application/x-7z-compressed", "application/x-7z-compressed", "application/x-tar", + "application/x-tar", + "application/zip", "application/zip", "application/gzip", "application/gzip",