Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,11 @@ 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`.
Aliases for these formats are also supported:
- `tar`: `tgz`, `tbz`, `tbz2`, `tlz4`, `txz`, `tlzma`, `tsz`, `tzst`, `cbt`
- `zip`: `cbz`
- `7z`: `cb7`
- `rar`: `cbr`

Formats can be chained:

Expand Down
20 changes: 10 additions & 10 deletions src/extension.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ 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";
#[cfg(feature = "unrar")]
pub const PRETTY_SUPPORTED_EXTENSIONS: &str = "tar, zip, bz, bz2, bz3, gz, lz4, xz, lzma, sz, zst, rar, 7z";

pub const PRETTY_SUPPORTED_ALIASES: &str = "tgz, tbz, tlz4, txz, tzlma, tsz, tzst";
pub const PRETTY_SUPPORTED_ALIASES: &str = "tgz, tbz, tlz4, txz, tzlma, tsz, tzst, cbt, cbz, cb7, cbr";

/// A wrapper around `CompressionFormat` that allows combinations like `tgz`
#[derive(Debug, Clone)]
Expand Down Expand Up @@ -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,
Expand All @@ -125,24 +125,24 @@ impl CompressionFormat {
fn to_extension(ext: &[u8]) -> Option<Extension> {
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],
b"tlz4" => &[Tar, Lz4],
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],
b"lz4" => &[Lz4],
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,
},
Expand Down
7 changes: 5 additions & 2 deletions tests/mime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,17 @@ 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",
"application/x-bzip2",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ expression: "run_ouch(\"ouch decompress a\", dir)"
- Decompression formats are detected automatically from file extension

hint: Supported extensions are: tar, zip, bz, bz2, bz3, gz, lz4, xz, lzma, sz, zst, rar, 7z
hint: Supported aliases are: tgz, tbz, tlz4, txz, tzlma, tsz, tzst
hint: Supported aliases are: tgz, tbz, tlz4, txz, tzlma, tsz, tzst, cbt, cbz, cb7, cbr
hint:
hint: Alternatively, you can pass an extension to the '--format' flag:
hint: ouch decompress <TMP_DIR>/a --format tar.gz
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ expression: "run_ouch(\"ouch decompress a b.unknown\", dir)"
- Decompression formats are detected automatically from file extension

hint: Supported extensions are: tar, zip, bz, bz2, bz3, gz, lz4, xz, lzma, sz, zst, rar, 7z
hint: Supported aliases are: tgz, tbz, tlz4, txz, tzlma, tsz, tzst
hint: Supported aliases are: tgz, tbz, tlz4, txz, tzlma, tsz, tzst, cbt, cbz, cb7, cbr
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ expression: "run_ouch(\"ouch decompress b.unknown\", dir)"
- Decompression formats are detected automatically from file extension

hint: Supported extensions are: tar, zip, bz, bz2, bz3, gz, lz4, xz, lzma, sz, zst, rar, 7z
hint: Supported aliases are: tgz, tbz, tlz4, txz, tzlma, tsz, tzst
hint: Supported aliases are: tgz, tbz, tlz4, txz, tzlma, tsz, tzst, cbt, cbz, cb7, cbr
hint:
hint: Alternatively, you can pass an extension to the '--format' flag:
hint: ouch decompress <TMP_DIR>/b.unknown --format tar.gz
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ expression: "run_ouch(\"ouch compress input output --format tar.gz.unknown\", di
- Unsupported extension 'unknown'

hint: Supported extensions are: tar, zip, bz, bz2, bz3, gz, lz4, xz, lzma, sz, zst, rar, 7z
hint: Supported aliases are: tgz, tbz, tlz4, txz, tzlma, tsz, tzst
hint: Supported aliases are: tgz, tbz, tlz4, txz, tzlma, tsz, tzst, cbt, cbz, cb7, cbr
hint:
hint: Examples:
hint: --format tar
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ expression: "run_ouch(\"ouch compress input output --format targz\", dir)"
- Unsupported extension 'targz'

hint: Supported extensions are: tar, zip, bz, bz2, bz3, gz, lz4, xz, lzma, sz, zst, rar, 7z
hint: Supported aliases are: tgz, tbz, tlz4, txz, tzlma, tsz, tzst
hint: Supported aliases are: tgz, tbz, tlz4, txz, tzlma, tsz, tzst, cbt, cbz, cb7, cbr
hint:
hint: Examples:
hint: --format tar
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ expression: "run_ouch(\"ouch compress input output --format .tar.$#[email protected]\", di
- Unsupported extension '$#!@'

hint: Supported extensions are: tar, zip, bz, bz2, bz3, gz, lz4, xz, lzma, sz, zst, rar, 7z
hint: Supported aliases are: tgz, tbz, tlz4, txz, tzlma, tsz, tzst
hint: Supported aliases are: tgz, tbz, tlz4, txz, tzlma, tsz, tzst, cbt, cbz, cb7, cbr
hint:
hint: Examples:
hint: --format tar
Expand Down