Skip to content

Commit 3096661

Browse files
committed
feat: Add support for lzip compression
1 parent aeb27cc commit 3096661

File tree

9 files changed

+43
-16
lines changed

9 files changed

+43
-16
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ Categories Used:
2727
- Provide Nushell completions (packages still need to install them) [\#827](https://github.com/ouch-org/ouch/pull/827) ([FrancescElies](https://github.com/FrancescElies))
2828
- Support `.lz` decompression [\#838](https://github.com/ouch-org/ouch/pull/838) ([zzzsyyy](https://github.com/zzzsyyy))
2929
- Support `.lzma` decompression (and fix `.lzma` being a wrong alias for `.xz`) [\#838](https://github.com/ouch-org/ouch/pull/838) ([zzzsyyy](https://github.com/zzzsyyy))
30+
- Support `.lz` compression [\#863](https://github.com/ouch-org/ouch/pull/863) ([sorairolake](https://github.com/sorairolake))
3031

3132
### Improvements
3233

Cargo.lock

Lines changed: 29 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ authors = [
66
"Vinícius Rodrigues Miguel <[email protected]>",
77
]
88
edition = "2021"
9+
rust-version = "1.85.0"
910
readme = "README.md"
1011
repository = "https://github.com/ouch-org/ouch"
1112
license = "MIT"
@@ -31,6 +32,7 @@ ignore = "0.4.23"
3132
libc = "0.2.155"
3233
linked-hash-map = "0.5.6"
3334
lz4_flex = "0.11.3"
35+
lzma-rust2 = "0.11.0"
3436
num_cpus = "1.16.0"
3537
once_cell = "1.20.2"
3638
rayon = "1.10.0"

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ Output:
113113

114114
| Format | `.tar` | `.zip` | `7z` | `.gz` | `.xz` | `.lzma` | `.lz` | `.bz`, `.bz2` | `.bz3` | `.lz4` | `.sz` (Snappy) | `.zst` | `.rar` | `.br` |
115115
|:---------:|:---:|:---:|:---:|:---:|:---:|:---:|:---:|:---:|:---:|:---:|:---:|:---:|:---:|:---:|
116-
| Supported || ✓¹ | ✓¹ | ✓² || ✓⁴ | |||| ✓² | ✓² | ✓³ ||
116+
| Supported || ✓¹ | ✓¹ | ✓² || ✓⁴ ||||| ✓² | ✓² | ✓³ ||
117117

118118
✓: Supports compression and decompression.
119119

src/commands/compress.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,11 @@ pub fn compress_files(
7878
level.map_or(6, |l| (l as u32).clamp(0, 9)),
7979
)),
8080
Lzip => {
81-
return Err(crate::Error::UnsupportedFormat {
82-
reason: "Lzip compression is not supported in ouch.".to_string(),
83-
})
81+
let options = level.map_or_else(Default::default, |l| {
82+
lzma_rust2::LZIPOptions::with_preset((l as u32).clamp(0, 9))
83+
});
84+
let writer = lzma_rust2::LZIPWriter::new(encoder, options);
85+
Box::new(writer.auto_finish())
8486
}
8587
Snappy => Box::new(
8688
gzp::par::compress::ParCompress::<gzp::snap::Snap>::builder()

src/commands/decompress.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -133,10 +133,7 @@ pub fn decompress_file(options: DecompressOptions) -> crate::Result<()> {
133133
liblzma::stream::Stream::new_lzma_decoder(u64::MAX).unwrap(),
134134
)),
135135
Xz => Box::new(liblzma::read::XzDecoder::new(decoder)),
136-
Lzip => Box::new(liblzma::read::XzDecoder::new_stream(
137-
decoder,
138-
liblzma::stream::Stream::new_lzip_decoder(u64::MAX, 0).unwrap(),
139-
)),
136+
Lzip => Box::new(lzma_rust2::LZIPReader::new(decoder)?),
140137
Snappy => Box::new(snap::read::FrameDecoder::new(decoder)),
141138
Zstd => Box::new(zstd::stream::Decoder::new(decoder)?),
142139
Brotli => Box::new(brotli::Decompressor::new(decoder, BUFFER_CAPACITY)),

src/commands/list.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,7 @@ pub fn list_archive_contents(
6262
liblzma::stream::Stream::new_lzma_decoder(u64::MAX).unwrap(),
6363
)),
6464
Xz => Box::new(liblzma::read::XzDecoder::new(decoder)),
65-
Lzip => Box::new(liblzma::read::XzDecoder::new_stream(
66-
decoder,
67-
liblzma::stream::Stream::new_lzip_decoder(u64::MAX, 0).unwrap(),
68-
)),
65+
Lzip => Box::new(lzma_rust2::LZIPReader::new(decoder)?),
6966
Snappy => Box::new(snap::read::FrameDecoder::new(decoder)),
7067
Zstd => Box::new(zstd::stream::Decoder::new(decoder)?),
7168
Brotli => Box::new(brotli::Decompressor::new(decoder, BUFFER_CAPACITY)),

src/extension.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ pub enum CompressionFormat {
9494
Lzip,
9595
/// .sz
9696
Snappy,
97-
/// tar, tgz, tbz, tbz2, tbz3, txz, tlz4, tlzma, tsz, tzst
97+
/// tar, tgz, tbz, tbz2, tbz3, txz, tlz, tlz4, tlzma, tsz, tzst
9898
Tar,
9999
/// .zst
100100
Zstd,

tests/integration.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ enum DirectoryExtension {
3232
#[cfg(feature = "bzip3")]
3333
Tbz3,
3434
Tgz,
35+
Tlz,
3536
Tlz4,
3637
Tsz,
3738
Txz,
@@ -48,6 +49,7 @@ enum FileExtension {
4849
#[cfg(feature = "bzip3")]
4950
Bz3,
5051
Gz,
52+
Lz,
5153
Lz4,
5254
Sz,
5355
Xz,

0 commit comments

Comments
 (0)