Skip to content

Commit

Permalink
update clap, refactor, support recovery record and fast mode
Browse files Browse the repository at this point in the history
  • Loading branch information
magiclen committed Nov 6, 2023
1 parent e777443 commit 8af6985
Show file tree
Hide file tree
Showing 11 changed files with 3,183 additions and 2,709 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci-version.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ jobs:
os:
- macos-latest
toolchain:
- "1.60"
- "1.70"
features:
-
name: Test ${{ matrix.toolchain }} on ${{ matrix.os }} (${{ matrix.features }})
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ jobs:
os:
- ubuntu-latest
toolchain:
- "1.60"
- "1.70"
target:
- x86_64-unknown-linux-gnu
- x86_64-unknown-linux-musl
Expand Down
16 changes: 9 additions & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
[package]
name = "xcompress"
version = "0.11.8"
version = "0.12.0"
authors = ["Magic Len <len@magiclen.org>"]
edition = "2021"
rust-version = "1.60"
rust-version = "1.70"
repository = "https://github.com/magiclen/xcompress"
homepage = "https://magiclen.org/xcompress"
keywords = ["compression", "decompression", "zip", "archive", "tar"]
Expand All @@ -19,13 +19,15 @@ panic = "abort"
strip = true

[dependencies]
clap = "3.2.23"
clap = { version = "4", features = ["derive"] }
concat-with = "0.2"
terminal_size = "0.2"
terminal_size = "0.3"

execute = "0.2.4"
num_cpus = "1.8.0"
scanner-rust = "2.0.9"
anyhow = "1"

execute = "0.2"
num_cpus = "1"
scanner-rust = "2"

[dependencies.path-absolutize]
version = "3"
Expand Down
77 changes: 38 additions & 39 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,45 +18,44 @@ xcompress x foo.rar # Extract foo.rar into current working
xcompress x foo.tar.gz /tmp/out_folder # Extract foo.tar.gz into /tmp/out_folder
xcompress x -p password foo.rar # Extract foo.rar with a password into current working directory
USAGE:
xcompress [OPTIONS] [SUBCOMMAND]
OPTIONS:
-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.
--7z-path <7Z_PATH> Specify the path of your 7z executable binary file. [default: 7z]
--bunzip2-path <BUNZIP2_PATH> Specify the path of your bunzip2 executable binary file. [default: bunzip2]
--bzip2-path <BZIP2_PATH> Specify the path of your bzip2 executable binary file. [default: bzip2]
--compress-path <COMPRESS_PATH> Specify the path of your compress executable binary file. [default: compress]
--gunzip-path <GUNZIP_PATH> Specify the path of your gunzip executable binary file. [default: gunzip]
--gzip-path <GZIP_PATH> Specify the path of your gzip executable binary file. [default: gzip]
-h, --help Print help information
--lbzip2-path <LBZIP2_PATH> Specify the path of your lbzip2 executable binary file. [default: lbzip2]
--lunzip-path <LUNZIP_PATH> Specify the path of your lunzip executable binary file. [default: lunzip]
--lzip-path <LZIP_PATH> Specify the path of your lzip executable binary file. [default: lzip]
--lzma-path <LZMA_PATH> Specify the path of your lzma executable binary file. [default: lzma]
--pbzip2-path <PBZIP2_PATH> Specify the path of your pbzip2 executable binary file. [default: pbzip2]
--pigz-path <PIGZ_PATH> Specify the path of your pigz executable binary file. [default: pigz]
--plzip-path <PLZIP_PATH> Specify the path of your plzip executable binary file. [default: plzip]
--pxz-path <PXZ_PATH> Specify the path of your pxz executable binary file. [default: pxz]
--pzstd-path <PZSTD_PATH> Specify the path of your pzstd executable binary file. [default: pzstd]
-q, --quiet Make programs not print anything on the screen.
--rar-path <RAR_PATH> Specify the path of your rar executable binary file. [default: rar]
-s, --single-thread Use only one thread.
--tar-path <TAR_PATH> Specify the path of your tar executable binary file. [default: tar]
--unlzma-path <UNLZMA_PATH> Specify the path of your unlzma executable binary file. [default: unlzma]
--unrar-path <UNRAR_PATH> Specify the path of your unrar executable binary file. [default: unrar]
--unxz-path <UNXZ_PATH> Specify the path of your unxz executable binary file. [default: unxz]
--unzip-path <UNZIP_PATH> Specify the path of your unzip executable binary file. [default: unzip]
--unzstd-path <UNZSTD_PATH> Specify the path of your unzstd executable binary file. [default: unzstd]
-V, --version Print version information
--xz-path <XZ_PATH> Specify the path of your xz executable binary file. [default: xz]
--zip-path <ZIP_PATH> Specify the path of your zip executable binary file. [default: zip]
--zstd-path <ZSTD_PATH> Specify the path of your zstd executable binary file. [default: zstd]
SUBCOMMANDS:
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.)
help Print this message or the help of the given subcommand(s)
x Extract files with full path.
Usage: xcompress [OPTIONS] <COMMAND>
Commands:
x Extract files with full path
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)
help Print this message or the help of the given subcommand(s)
Options:
-q, --quiet Make programs not print anything on the screen
-s, --single-thread Use only one thread
-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
--compress-path <COMPRESS_PATH> Specify the path of your compress executable binary file [default: compress]
--zip-path <ZIP_PATH> Specify the path of your zip executable binary file [default: zip]
--unzip-path <UNZIP_PATH> Specify the path of your unzip executable binary file [default: unzip]
--gzip-path <GZIP_PATH> Specify the path of your gzip executable binary file [default: gzip]
--gnuzip-path <GNUZIP_PATH> Specify the path of your gunzip executable binary file [default: gunzip]
--pigz-path <PIGZ_PATH> Specify the path of your pigz executable binary file [default: pigz]
--bzip2-path <BZIP2_PATH> Specify the path of your bzip2 executable binary file [default: bzip2]
--bunzip2-path <BUNZIP2_PATH> Specify the path of your bunzip2 executable binary file [default: bunzip2]
--lbzip2-path <LBZIP2_PATH> Specify the path of your lbzip2 executable binary file [default: lbzip2]
--pbzip2-path <PBZIP2_PATH> Specify the path of your pbzip2 executable binary file [default: pbzip2]
--lzip-path <LZIP_PATH> Specify the path of your lzip executable binary file [default: lzip]
--lunzip-path <LUNZIP_PATH> Specify the path of your lunzip executable binary file [default: lunzip]
--plzip-path <PLZIP_PATH> Specify the path of your plzip executable binary file [default: plzip]
--xz-path <XZ_PATH> Specify the path of your xz executable binary file [default: xz]
--unxz-path <UNXZ_PATH> Specify the path of your unxz executable binary file [default: unxz]
--pxz-path <PXZ_PATH> Specify the path of your pxz executable binary file [default: pxz]
--lzma-path <LZMA_PATH> Specify the path of your lzma executable binary file [default: lzma]
--unlzma-path <UNLZMA_PATH> Specify the path of your unlzma executable binary file [default: unlzma]
--7Z_PATH <P7Z_PATH> Specify the path of your 7z executable binary file [default: 7z]
--tar-path <TAR_PATH> Specify the path of your tar executable binary file [default: tar]
--rar-path <RAR_PATH> Specify the path of your rar executable binary file [default: rar]
--unrar-path <UNRAR_PATH> Specify the path of your unrar executable binary file [default: unrar]
--zstd-path <ZSTD_PATH> Specify the path of your zstd executable binary file [default: zstd]
--unzstd-path <UNZSTD_PATH> Specify the path of your unzstd executable binary file [default: unzstd]
--pzstd-path <PZSTD_PATH> Specify the path of your pzstd executable binary file [default: pzstd]
-h, --help Print help
-V, --version Print version
```

## License
Expand Down
85 changes: 85 additions & 0 deletions src/archive_format.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
use std::path::Path;

use anyhow::anyhow;

#[derive(Debug)]
pub enum ArchiveFormat {
Z,
Zip,
Gzip,
Bzip2,
Lz,
Xz,
Lzma,
P7z,
Tar,
TarZ,
TarGzip,
TarBzip2,
TarLz,
TarXz,
TarLzma,
Tar7z,
TarZstd,
Rar,
Zstd,
}

impl ArchiveFormat {
pub fn get_archive_format_from_file_path<P: AsRef<Path>>(
file_path: P,
) -> anyhow::Result<ArchiveFormat> {
let file_path = file_path.as_ref();

if let Some(file_name) = file_path.file_name() {
if let Some(file_name) = file_name.to_str() {
let file_name = file_name.to_ascii_lowercase();

if file_name.ends_with("tar.z") {
return Ok(ArchiveFormat::TarZ);
} else if file_name.ends_with(".tar.gz") || file_name.ends_with(".tgz") {
return Ok(ArchiveFormat::TarGzip);
} else if file_name.ends_with(".tar.bz2") || file_name.ends_with(".tbz2") {
return Ok(ArchiveFormat::TarBzip2);
} else if file_name.ends_with(".tar.lz") {
return Ok(ArchiveFormat::TarLz);
} else if file_name.ends_with(".tar.xz") || file_name.ends_with(".txz") {
return Ok(ArchiveFormat::TarXz);
} else if file_name.ends_with(".tar.lzma") || file_name.ends_with(".tlz") {
return Ok(ArchiveFormat::TarLzma);
} else if file_name.ends_with(".tar.7z")
|| file_name.ends_with(".tar.7z.001")
|| file_name.ends_with(".t7z")
{
return Ok(ArchiveFormat::Tar7z);
} else if file_name.ends_with(".tar.zst") {
return Ok(ArchiveFormat::TarZstd);
} else if file_name.ends_with(".tar") {
return Ok(ArchiveFormat::Tar);
} else if file_name.ends_with(".z") {
return Ok(ArchiveFormat::Z);
} else if file_name.ends_with(".zip") {
return Ok(ArchiveFormat::Zip);
} else if file_name.ends_with(".gz") {
return Ok(ArchiveFormat::Gzip);
} else if file_name.ends_with(".bz2") {
return Ok(ArchiveFormat::Bzip2);
} else if file_name.ends_with(".lz") {
return Ok(ArchiveFormat::Lz);
} else if file_name.ends_with(".xz") {
return Ok(ArchiveFormat::Xz);
} else if file_name.ends_with(".lzma") {
return Ok(ArchiveFormat::Lzma);
} else if file_name.ends_with(".7z") || file_name.ends_with(".7z.001") {
return Ok(ArchiveFormat::P7z);
} else if file_name.ends_with(".rar") {
return Ok(ArchiveFormat::Rar);
} else if file_name.ends_with(".zst") {
return Ok(ArchiveFormat::Zstd);
}
}
}

Err(anyhow!("Unknown archive format."))
}
}
Loading

0 comments on commit 8af6985

Please sign in to comment.