summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKalle Samuels <charles@derkarl.org>2018-04-27 09:37:53 +0000
committerAndrew Gallant <jamslam@gmail.com>2018-07-21 16:26:39 -0400
commit1d09d4d31ba3ac2eb09edf31e8ec46b2b5cec388 (patch)
treef1f9696f5a37500d3b4ae0b6d6f452ab77a1d7b4
parent02f08f3800611c214f8f51cd3bf8fcc9b24de331 (diff)
ripgrep: add support for lz4 decompression
This uses the lz4 binary for decompression. Closes #898
-rw-r--r--.travis.yml1
-rw-r--r--CHANGELOG.md2
-rw-r--r--FAQ.md2
-rw-r--r--README.md2
-rw-r--r--ignore/src/types.rs1
-rw-r--r--src/app.rs2
-rw-r--r--src/decompressor.rs3
-rw-r--r--tests/data/sherlock.lz4bin0 -> 365 bytes
-rw-r--r--tests/tests.rs20
9 files changed, 30 insertions, 3 deletions
diff --git a/.travis.yml b/.travis.yml
index 7c2c7f93..5fc57d60 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -16,6 +16,7 @@ addons:
- zsh
# Needed for testing decompression search.
- xz-utils
+ - liblz4-tool
matrix:
fast_finish: true
include:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index c7105c55..b2130854 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -42,6 +42,8 @@ Feature enhancements:
Add `--count-matches` flag, which is like `--count`, but for each match.
* [FEATURE #880](https://github.com/BurntSushi/ripgrep/issues/880):
Add a `--no-column` flag, which disables column numbers in the output.
+* [FEATURE #898](https://github.com/BurntSushi/ripgrep/issues/898):
+ Add support for `lz4` when using the `-z/--search-zip` flag.
* [FEATURE #924](https://github.com/BurntSushi/ripgrep/issues/924):
`termcolor` has moved to its own repository:
https://github.com/BurntSushi/termcolor
diff --git a/FAQ.md b/FAQ.md
index c98bafc5..868c4723 100644
--- a/FAQ.md
+++ b/FAQ.md
@@ -135,7 +135,7 @@ How do I search compressed files?
</h3>
ripgrep's `-z/--search-zip` flag will cause it to search compressed files
-automatically. Currently, this supports gzip, bzip2, lzma and xz only and
+automatically. Currently, this supports gzip, bzip2, lzma, lz4 and xz only and
requires the corresponding `gzip`, `bzip2` and `xz` binaries to be installed on
your system. (That is, ripgrep does decompression by shelling out to another
process.)
diff --git a/README.md b/README.md
index dfa1c94d..57ad0d7c 100644
--- a/README.md
+++ b/README.md
@@ -106,7 +106,7 @@ increases the times to `2.640s` for ripgrep and `10.277s` for GNU grep.
automatically detecting UTF-16 is provided. Other text encodings must be
specifically specified with the `-E/--encoding` flag.)
* ripgrep supports searching files compressed in a common format (gzip, xz,
- lzma or bzip2 current) with the `-z/--search-zip` flag.
+ lzma, bzip2 or lz4) with the `-z/--search-zip` flag.
In other words, use ripgrep if you like speed, filtering by default, fewer
bugs, and Unicode support.
diff --git a/ignore/src/types.rs b/ignore/src/types.rs
index 3f96f8e6..8ecbb2b0 100644
--- a/ignore/src/types.rs
+++ b/ignore/src/types.rs
@@ -193,6 +193,7 @@ const DEFAULT_TYPES: &'static [(&'static str, &'static [&'static str])] = &[
("log", &["*.log"]),
("lua", &["*.lua"]),
("lzma", &["*.lzma"]),
+ ("lz4", &["*.lz4"]),
("m4", &["*.ac", "*.m4"]),
("make", &[
"gnumakefile", "Gnumakefile", "GNUmakefile",
diff --git a/src/app.rs b/src/app.rs
index 5728371f..a0fdf946 100644
--- a/src/app.rs
+++ b/src/app.rs
@@ -1445,7 +1445,7 @@ This flag can be used with the -o/--only-matching flag.
fn flag_search_zip(args: &mut Vec<RGArg>) {
const SHORT: &str = "Search in compressed files.";
const LONG: &str = long!("\
-Search in compressed files. Currently gz, bz2, xz, and lzma files are
+Search in compressed files. Currently gz, bz2, xz, lzma and lz4 files are
supported. This option expects the decompression binaries to be available in
your PATH.
diff --git a/src/decompressor.rs b/src/decompressor.rs
index a94948af..235849b7 100644
--- a/src/decompressor.rs
+++ b/src/decompressor.rs
@@ -44,6 +44,7 @@ lazy_static! {
m.insert("gz", DecompressionCommand::new("gzip", ARGS));
m.insert("bz2", DecompressionCommand::new("bzip2", ARGS));
m.insert("xz", DecompressionCommand::new("xz", ARGS));
+ m.insert("lz4", DecompressionCommand::new("lz4", ARGS));
const LZMA_ARGS: &[&str] = &["--format=lzma", "-d", "-c"];
m.insert("lzma", DecompressionCommand::new("xz", LZMA_ARGS));
@@ -55,6 +56,7 @@ lazy_static! {
builder.add(Glob::new("*.gz").unwrap());
builder.add(Glob::new("*.bz2").unwrap());
builder.add(Glob::new("*.xz").unwrap());
+ builder.add(Glob::new("*.lz4").unwrap());
builder.add(Glob::new("*.lzma").unwrap());
builder.build().unwrap()
};
@@ -63,6 +65,7 @@ lazy_static! {
builder.add(Glob::new("*.tar.gz").unwrap());
builder.add(Glob::new("*.tar.xz").unwrap());
builder.add(Glob::new("*.tar.bz2").unwrap());
+ builder.add(Glob::new("*.tar.lz4").unwrap());
builder.add(Glob::new("*.tgz").unwrap());
builder.add(Glob::new("*.txz").unwrap());
builder.add(Glob::new("*.tbz2").unwrap());
diff --git a/tests/data/sherlock.lz4 b/tests/data/sherlock.lz4
new file mode 100644
index 00000000..5913dbba
--- /dev/null
+++ b/tests/data/sherlock.lz4
Binary files differ
diff --git a/tests/tests.rs b/tests/tests.rs
index f3cc8f06..9920c118 100644
--- a/tests/tests.rs
+++ b/tests/tests.rs
@@ -1793,6 +1793,26 @@ be, to a very large extent, the result of luck. Sherlock Holmes
}
#[test]
+fn compressed_lz4() {
+ if !cmd_exists("lz4") {
+ return;
+ }
+ let lz4_file = include_bytes!("./data/sherlock.lz4");
+
+ let wd = WorkDir::new("feature_search_compressed");
+ wd.create_bytes("sherlock.lz4", lz4_file);
+
+ let mut cmd = wd.command();
+ cmd.arg("-z").arg("Sherlock").arg("sherlock.lz4");
+ let lines: String = wd.stdout(&mut cmd);
+ let expected = "\
+For the Doctor Watsons of this world, as opposed to the Sherlock
+be, to a very large extent, the result of luck. Sherlock Holmes
+";
+ assert_eq!(lines, expected);
+}
+
+#[test]
fn compressed_lzma() {
if !cmd_exists("xz") {
return;