From 1d09d4d31ba3ac2eb09edf31e8ec46b2b5cec388 Mon Sep 17 00:00:00 2001 From: Kalle Samuels Date: Fri, 27 Apr 2018 09:37:53 +0000 Subject: ripgrep: add support for lz4 decompression This uses the lz4 binary for decompression. Closes #898 --- .travis.yml | 1 + CHANGELOG.md | 2 ++ FAQ.md | 2 +- README.md | 2 +- ignore/src/types.rs | 1 + src/app.rs | 2 +- src/decompressor.rs | 3 +++ tests/data/sherlock.lz4 | Bin 0 -> 365 bytes tests/tests.rs | 20 ++++++++++++++++++++ 9 files changed, 30 insertions(+), 3 deletions(-) create mode 100644 tests/data/sherlock.lz4 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? 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) { 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 Binary files /dev/null and b/tests/data/sherlock.lz4 differ diff --git a/tests/tests.rs b/tests/tests.rs index f3cc8f06..9920c118 100644 --- a/tests/tests.rs +++ b/tests/tests.rs @@ -1792,6 +1792,26 @@ be, to a very large extent, the result of luck. Sherlock Holmes assert_eq!(lines, expected); } +#[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") { -- cgit v1.2.3