Skip to content

Commit 8af6985

Browse files
committed
update clap, refactor, support recovery record and fast mode
1 parent e777443 commit 8af6985

File tree

11 files changed

+3183
-2709
lines changed

11 files changed

+3183
-2709
lines changed

.github/workflows/ci-version.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ jobs:
8585
os:
8686
- macos-latest
8787
toolchain:
88-
- "1.60"
88+
- "1.70"
8989
features:
9090
-
9191
name: Test ${{ matrix.toolchain }} on ${{ matrix.os }} (${{ matrix.features }})

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ jobs:
7878
os:
7979
- ubuntu-latest
8080
toolchain:
81-
- "1.60"
81+
- "1.70"
8282
target:
8383
- x86_64-unknown-linux-gnu
8484
- x86_64-unknown-linux-musl

Cargo.toml

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
[package]
22
name = "xcompress"
3-
version = "0.11.8"
3+
version = "0.12.0"
44
authors = ["Magic Len <[email protected]>"]
55
edition = "2021"
6-
rust-version = "1.60"
6+
rust-version = "1.70"
77
repository = "https://github.com/magiclen/xcompress"
88
homepage = "https://magiclen.org/xcompress"
99
keywords = ["compression", "decompression", "zip", "archive", "tar"]
@@ -19,13 +19,15 @@ panic = "abort"
1919
strip = true
2020

2121
[dependencies]
22-
clap = "3.2.23"
22+
clap = { version = "4", features = ["derive"] }
2323
concat-with = "0.2"
24-
terminal_size = "0.2"
24+
terminal_size = "0.3"
2525

26-
execute = "0.2.4"
27-
num_cpus = "1.8.0"
28-
scanner-rust = "2.0.9"
26+
anyhow = "1"
27+
28+
execute = "0.2"
29+
num_cpus = "1"
30+
scanner-rust = "2"
2931

3032
[dependencies.path-absolutize]
3133
version = "3"

README.md

Lines changed: 38 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -18,45 +18,44 @@ xcompress x foo.rar # Extract foo.rar into current working
1818
xcompress x foo.tar.gz /tmp/out_folder # Extract foo.tar.gz into /tmp/out_folder
1919
xcompress x -p password foo.rar # Extract foo.rar with a password into current working directory
2020
21-
USAGE:
22-
xcompress [OPTIONS] [SUBCOMMAND]
23-
24-
OPTIONS:
25-
-p, --password <PASSWORD> Set password for your archive file. (Only supports 7Z, ZIP and RAR.) Set an empty string to read a password from stdin.
26-
--7z-path <7Z_PATH> Specify the path of your 7z executable binary file. [default: 7z]
27-
--bunzip2-path <BUNZIP2_PATH> Specify the path of your bunzip2 executable binary file. [default: bunzip2]
28-
--bzip2-path <BZIP2_PATH> Specify the path of your bzip2 executable binary file. [default: bzip2]
29-
--compress-path <COMPRESS_PATH> Specify the path of your compress executable binary file. [default: compress]
30-
--gunzip-path <GUNZIP_PATH> Specify the path of your gunzip executable binary file. [default: gunzip]
31-
--gzip-path <GZIP_PATH> Specify the path of your gzip executable binary file. [default: gzip]
32-
-h, --help Print help information
33-
--lbzip2-path <LBZIP2_PATH> Specify the path of your lbzip2 executable binary file. [default: lbzip2]
34-
--lunzip-path <LUNZIP_PATH> Specify the path of your lunzip executable binary file. [default: lunzip]
35-
--lzip-path <LZIP_PATH> Specify the path of your lzip executable binary file. [default: lzip]
36-
--lzma-path <LZMA_PATH> Specify the path of your lzma executable binary file. [default: lzma]
37-
--pbzip2-path <PBZIP2_PATH> Specify the path of your pbzip2 executable binary file. [default: pbzip2]
38-
--pigz-path <PIGZ_PATH> Specify the path of your pigz executable binary file. [default: pigz]
39-
--plzip-path <PLZIP_PATH> Specify the path of your plzip executable binary file. [default: plzip]
40-
--pxz-path <PXZ_PATH> Specify the path of your pxz executable binary file. [default: pxz]
41-
--pzstd-path <PZSTD_PATH> Specify the path of your pzstd executable binary file. [default: pzstd]
42-
-q, --quiet Make programs not print anything on the screen.
43-
--rar-path <RAR_PATH> Specify the path of your rar executable binary file. [default: rar]
44-
-s, --single-thread Use only one thread.
45-
--tar-path <TAR_PATH> Specify the path of your tar executable binary file. [default: tar]
46-
--unlzma-path <UNLZMA_PATH> Specify the path of your unlzma executable binary file. [default: unlzma]
47-
--unrar-path <UNRAR_PATH> Specify the path of your unrar executable binary file. [default: unrar]
48-
--unxz-path <UNXZ_PATH> Specify the path of your unxz executable binary file. [default: unxz]
49-
--unzip-path <UNZIP_PATH> Specify the path of your unzip executable binary file. [default: unzip]
50-
--unzstd-path <UNZSTD_PATH> Specify the path of your unzstd executable binary file. [default: unzstd]
51-
-V, --version Print version information
52-
--xz-path <XZ_PATH> Specify the path of your xz executable binary file. [default: xz]
53-
--zip-path <ZIP_PATH> Specify the path of your zip executable binary file. [default: zip]
54-
--zstd-path <ZSTD_PATH> Specify the path of your zstd executable binary file. [default: zstd]
55-
56-
SUBCOMMANDS:
57-
a Add files to archive. Excludes base directory from names. (e.g. add /path/to/folder, you can always get the "folder" in the root of the archive file, instead of /path/to/folder.)
58-
help Print this message or the help of the given subcommand(s)
59-
x Extract files with full path.
21+
Usage: xcompress [OPTIONS] <COMMAND>
22+
23+
Commands:
24+
x Extract files with full path
25+
a Add files to archive. Excludes base directory from names (e.g. add /path/to/folder, you can always get the "folder" in the root of the archive file, instead of /path/to/folder)
26+
help Print this message or the help of the given subcommand(s)
27+
28+
Options:
29+
-q, --quiet Make programs not print anything on the screen
30+
-s, --single-thread Use only one thread
31+
-p, --password <PASSWORD> Set password for your archive file. (Only supports 7Z, ZIP and RAR) Set an empty string to read a password from stdin
32+
--compress-path <COMPRESS_PATH> Specify the path of your compress executable binary file [default: compress]
33+
--zip-path <ZIP_PATH> Specify the path of your zip executable binary file [default: zip]
34+
--unzip-path <UNZIP_PATH> Specify the path of your unzip executable binary file [default: unzip]
35+
--gzip-path <GZIP_PATH> Specify the path of your gzip executable binary file [default: gzip]
36+
--gnuzip-path <GNUZIP_PATH> Specify the path of your gunzip executable binary file [default: gunzip]
37+
--pigz-path <PIGZ_PATH> Specify the path of your pigz executable binary file [default: pigz]
38+
--bzip2-path <BZIP2_PATH> Specify the path of your bzip2 executable binary file [default: bzip2]
39+
--bunzip2-path <BUNZIP2_PATH> Specify the path of your bunzip2 executable binary file [default: bunzip2]
40+
--lbzip2-path <LBZIP2_PATH> Specify the path of your lbzip2 executable binary file [default: lbzip2]
41+
--pbzip2-path <PBZIP2_PATH> Specify the path of your pbzip2 executable binary file [default: pbzip2]
42+
--lzip-path <LZIP_PATH> Specify the path of your lzip executable binary file [default: lzip]
43+
--lunzip-path <LUNZIP_PATH> Specify the path of your lunzip executable binary file [default: lunzip]
44+
--plzip-path <PLZIP_PATH> Specify the path of your plzip executable binary file [default: plzip]
45+
--xz-path <XZ_PATH> Specify the path of your xz executable binary file [default: xz]
46+
--unxz-path <UNXZ_PATH> Specify the path of your unxz executable binary file [default: unxz]
47+
--pxz-path <PXZ_PATH> Specify the path of your pxz executable binary file [default: pxz]
48+
--lzma-path <LZMA_PATH> Specify the path of your lzma executable binary file [default: lzma]
49+
--unlzma-path <UNLZMA_PATH> Specify the path of your unlzma executable binary file [default: unlzma]
50+
--7Z_PATH <P7Z_PATH> Specify the path of your 7z executable binary file [default: 7z]
51+
--tar-path <TAR_PATH> Specify the path of your tar executable binary file [default: tar]
52+
--rar-path <RAR_PATH> Specify the path of your rar executable binary file [default: rar]
53+
--unrar-path <UNRAR_PATH> Specify the path of your unrar executable binary file [default: unrar]
54+
--zstd-path <ZSTD_PATH> Specify the path of your zstd executable binary file [default: zstd]
55+
--unzstd-path <UNZSTD_PATH> Specify the path of your unzstd executable binary file [default: unzstd]
56+
--pzstd-path <PZSTD_PATH> Specify the path of your pzstd executable binary file [default: pzstd]
57+
-h, --help Print help
58+
-V, --version Print version
6059
```
6160

6261
## License

src/archive_format.rs

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
use std::path::Path;
2+
3+
use anyhow::anyhow;
4+
5+
#[derive(Debug)]
6+
pub enum ArchiveFormat {
7+
Z,
8+
Zip,
9+
Gzip,
10+
Bzip2,
11+
Lz,
12+
Xz,
13+
Lzma,
14+
P7z,
15+
Tar,
16+
TarZ,
17+
TarGzip,
18+
TarBzip2,
19+
TarLz,
20+
TarXz,
21+
TarLzma,
22+
Tar7z,
23+
TarZstd,
24+
Rar,
25+
Zstd,
26+
}
27+
28+
impl ArchiveFormat {
29+
pub fn get_archive_format_from_file_path<P: AsRef<Path>>(
30+
file_path: P,
31+
) -> anyhow::Result<ArchiveFormat> {
32+
let file_path = file_path.as_ref();
33+
34+
if let Some(file_name) = file_path.file_name() {
35+
if let Some(file_name) = file_name.to_str() {
36+
let file_name = file_name.to_ascii_lowercase();
37+
38+
if file_name.ends_with("tar.z") {
39+
return Ok(ArchiveFormat::TarZ);
40+
} else if file_name.ends_with(".tar.gz") || file_name.ends_with(".tgz") {
41+
return Ok(ArchiveFormat::TarGzip);
42+
} else if file_name.ends_with(".tar.bz2") || file_name.ends_with(".tbz2") {
43+
return Ok(ArchiveFormat::TarBzip2);
44+
} else if file_name.ends_with(".tar.lz") {
45+
return Ok(ArchiveFormat::TarLz);
46+
} else if file_name.ends_with(".tar.xz") || file_name.ends_with(".txz") {
47+
return Ok(ArchiveFormat::TarXz);
48+
} else if file_name.ends_with(".tar.lzma") || file_name.ends_with(".tlz") {
49+
return Ok(ArchiveFormat::TarLzma);
50+
} else if file_name.ends_with(".tar.7z")
51+
|| file_name.ends_with(".tar.7z.001")
52+
|| file_name.ends_with(".t7z")
53+
{
54+
return Ok(ArchiveFormat::Tar7z);
55+
} else if file_name.ends_with(".tar.zst") {
56+
return Ok(ArchiveFormat::TarZstd);
57+
} else if file_name.ends_with(".tar") {
58+
return Ok(ArchiveFormat::Tar);
59+
} else if file_name.ends_with(".z") {
60+
return Ok(ArchiveFormat::Z);
61+
} else if file_name.ends_with(".zip") {
62+
return Ok(ArchiveFormat::Zip);
63+
} else if file_name.ends_with(".gz") {
64+
return Ok(ArchiveFormat::Gzip);
65+
} else if file_name.ends_with(".bz2") {
66+
return Ok(ArchiveFormat::Bzip2);
67+
} else if file_name.ends_with(".lz") {
68+
return Ok(ArchiveFormat::Lz);
69+
} else if file_name.ends_with(".xz") {
70+
return Ok(ArchiveFormat::Xz);
71+
} else if file_name.ends_with(".lzma") {
72+
return Ok(ArchiveFormat::Lzma);
73+
} else if file_name.ends_with(".7z") || file_name.ends_with(".7z.001") {
74+
return Ok(ArchiveFormat::P7z);
75+
} else if file_name.ends_with(".rar") {
76+
return Ok(ArchiveFormat::Rar);
77+
} else if file_name.ends_with(".zst") {
78+
return Ok(ArchiveFormat::Zstd);
79+
}
80+
}
81+
}
82+
83+
Err(anyhow!("Unknown archive format."))
84+
}
85+
}

0 commit comments

Comments
 (0)