Skip to content

Commit df7a3bf

Browse files
mineoBurntSushi
authored andcommitted
grep-cli: support files compressed by compress(1)
While Linux distributions (at least Arch Linux, RHEL, Debian) do not support compressing files with compress(1), macOS & AIX do (the utility is part of POSIX). Additionally, gzip is able to uncompress such compressed files and provides an `uncompress` binary. Closes #1547
1 parent 28f2a93 commit df7a3bf

File tree

5 files changed

+23
-0
lines changed

5 files changed

+23
-0
lines changed

CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
TBD
22
===
3+
Feature enhancements:
4+
5+
* [FEATURE #1547](https://github.com/BurntSushi/ripgrep/pull/1547):
6+
Support decompressing `.Z` files via `uncompress`.
7+
38
Bug fixes:
49

510
* [BUG #1252](https://github.com/BurntSushi/ripgrep/issues/1252):

crates/cli/src/decompress.rs

+2
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,7 @@ fn default_decompression_commands() -> Vec<DecompressionCommand> {
348348
const ARGS_LZMA: &[&str] = &["xz", "--format=lzma", "-d", "-c"];
349349
const ARGS_BROTLI: &[&str] = &["brotli", "-d", "-c"];
350350
const ARGS_ZSTD: &[&str] = &["zstd", "-q", "-d", "-c"];
351+
const ARGS_UNCOMPRESS: &[&str] = &["uncompress", "-c"];
351352

352353
fn cmd(glob: &str, args: &[&str]) -> DecompressionCommand {
353354
DecompressionCommand {
@@ -372,5 +373,6 @@ fn default_decompression_commands() -> Vec<DecompressionCommand> {
372373
cmd("*.br", ARGS_BROTLI),
373374
cmd("*.zst", ARGS_ZSTD),
374375
cmd("*.zstd", ARGS_ZSTD),
376+
cmd("*.Z", ARGS_UNCOMPRESS),
375377
]
376378
}

crates/ignore/src/default_types.rs

+1
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,7 @@ pub const DEFAULT_TYPES: &[(&str, &[&str])] = &[
234234
("xz", &["*.xz", "*.txz"]),
235235
("yacc", &["*.y"]),
236236
("yaml", &["*.yaml", "*.yml"]),
237+
("z", &["*.Z"]),
237238
("zig", &["*.zig"]),
238239
("zsh", &[
239240
".zshenv", "zshenv",

tests/data/sherlock.Z

286 Bytes
Binary file not shown.

tests/misc.rs

+15
Original file line numberDiff line numberDiff line change
@@ -970,6 +970,21 @@ be, to a very large extent, the result of luck. Sherlock Holmes
970970
eqnice!(expected, cmd.stdout());
971971
});
972972

973+
rgtest!(compressed_uncompress, |dir: Dir, mut cmd: TestCommand| {
974+
if !cmd_exists("uncompress") {
975+
return;
976+
}
977+
978+
dir.create_bytes("sherlock.Z", include_bytes!("./data/sherlock.Z"));
979+
cmd.arg("-z").arg("Sherlock").arg("sherlock.Z");
980+
981+
let expected = "\
982+
For the Doctor Watsons of this world, as opposed to the Sherlock
983+
be, to a very large extent, the result of luck. Sherlock Holmes
984+
";
985+
eqnice!(expected, cmd.stdout());
986+
});
987+
973988
rgtest!(compressed_failing_gzip, |dir: Dir, mut cmd: TestCommand| {
974989
if !cmd_exists("gzip") {
975990
return;

0 commit comments

Comments
 (0)