mirror of
https://github.com/BurntSushi/ripgrep.git
synced 2025-05-19 01:30:21 -07:00
ripgrep: add support for lz4 decompression
This uses the lz4 binary for decompression. Closes #898
This commit is contained in:
parent
02f08f3800
commit
1d09d4d31b
@ -16,6 +16,7 @@ addons:
|
|||||||
- zsh
|
- zsh
|
||||||
# Needed for testing decompression search.
|
# Needed for testing decompression search.
|
||||||
- xz-utils
|
- xz-utils
|
||||||
|
- liblz4-tool
|
||||||
matrix:
|
matrix:
|
||||||
fast_finish: true
|
fast_finish: true
|
||||||
include:
|
include:
|
||||||
|
@ -42,6 +42,8 @@ Feature enhancements:
|
|||||||
Add `--count-matches` flag, which is like `--count`, but for each match.
|
Add `--count-matches` flag, which is like `--count`, but for each match.
|
||||||
* [FEATURE #880](https://github.com/BurntSushi/ripgrep/issues/880):
|
* [FEATURE #880](https://github.com/BurntSushi/ripgrep/issues/880):
|
||||||
Add a `--no-column` flag, which disables column numbers in the output.
|
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):
|
* [FEATURE #924](https://github.com/BurntSushi/ripgrep/issues/924):
|
||||||
`termcolor` has moved to its own repository:
|
`termcolor` has moved to its own repository:
|
||||||
https://github.com/BurntSushi/termcolor
|
https://github.com/BurntSushi/termcolor
|
||||||
|
2
FAQ.md
2
FAQ.md
@ -135,7 +135,7 @@ How do I search compressed files?
|
|||||||
</h3>
|
</h3>
|
||||||
|
|
||||||
ripgrep's `-z/--search-zip` flag will cause it to 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
|
requires the corresponding `gzip`, `bzip2` and `xz` binaries to be installed on
|
||||||
your system. (That is, ripgrep does decompression by shelling out to another
|
your system. (That is, ripgrep does decompression by shelling out to another
|
||||||
process.)
|
process.)
|
||||||
|
@ -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
|
automatically detecting UTF-16 is provided. Other text encodings must be
|
||||||
specifically specified with the `-E/--encoding` flag.)
|
specifically specified with the `-E/--encoding` flag.)
|
||||||
* ripgrep supports searching files compressed in a common format (gzip, xz,
|
* 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
|
In other words, use ripgrep if you like speed, filtering by default, fewer
|
||||||
bugs, and Unicode support.
|
bugs, and Unicode support.
|
||||||
|
@ -193,6 +193,7 @@ const DEFAULT_TYPES: &'static [(&'static str, &'static [&'static str])] = &[
|
|||||||
("log", &["*.log"]),
|
("log", &["*.log"]),
|
||||||
("lua", &["*.lua"]),
|
("lua", &["*.lua"]),
|
||||||
("lzma", &["*.lzma"]),
|
("lzma", &["*.lzma"]),
|
||||||
|
("lz4", &["*.lz4"]),
|
||||||
("m4", &["*.ac", "*.m4"]),
|
("m4", &["*.ac", "*.m4"]),
|
||||||
("make", &[
|
("make", &[
|
||||||
"gnumakefile", "Gnumakefile", "GNUmakefile",
|
"gnumakefile", "Gnumakefile", "GNUmakefile",
|
||||||
|
@ -1445,7 +1445,7 @@ This flag can be used with the -o/--only-matching flag.
|
|||||||
fn flag_search_zip(args: &mut Vec<RGArg>) {
|
fn flag_search_zip(args: &mut Vec<RGArg>) {
|
||||||
const SHORT: &str = "Search in compressed files.";
|
const SHORT: &str = "Search in compressed files.";
|
||||||
const LONG: &str = long!("\
|
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
|
supported. This option expects the decompression binaries to be available in
|
||||||
your PATH.
|
your PATH.
|
||||||
|
|
||||||
|
@ -44,6 +44,7 @@ lazy_static! {
|
|||||||
m.insert("gz", DecompressionCommand::new("gzip", ARGS));
|
m.insert("gz", DecompressionCommand::new("gzip", ARGS));
|
||||||
m.insert("bz2", DecompressionCommand::new("bzip2", ARGS));
|
m.insert("bz2", DecompressionCommand::new("bzip2", ARGS));
|
||||||
m.insert("xz", DecompressionCommand::new("xz", ARGS));
|
m.insert("xz", DecompressionCommand::new("xz", ARGS));
|
||||||
|
m.insert("lz4", DecompressionCommand::new("lz4", ARGS));
|
||||||
|
|
||||||
const LZMA_ARGS: &[&str] = &["--format=lzma", "-d", "-c"];
|
const LZMA_ARGS: &[&str] = &["--format=lzma", "-d", "-c"];
|
||||||
m.insert("lzma", DecompressionCommand::new("xz", LZMA_ARGS));
|
m.insert("lzma", DecompressionCommand::new("xz", LZMA_ARGS));
|
||||||
@ -55,6 +56,7 @@ lazy_static! {
|
|||||||
builder.add(Glob::new("*.gz").unwrap());
|
builder.add(Glob::new("*.gz").unwrap());
|
||||||
builder.add(Glob::new("*.bz2").unwrap());
|
builder.add(Glob::new("*.bz2").unwrap());
|
||||||
builder.add(Glob::new("*.xz").unwrap());
|
builder.add(Glob::new("*.xz").unwrap());
|
||||||
|
builder.add(Glob::new("*.lz4").unwrap());
|
||||||
builder.add(Glob::new("*.lzma").unwrap());
|
builder.add(Glob::new("*.lzma").unwrap());
|
||||||
builder.build().unwrap()
|
builder.build().unwrap()
|
||||||
};
|
};
|
||||||
@ -63,6 +65,7 @@ lazy_static! {
|
|||||||
builder.add(Glob::new("*.tar.gz").unwrap());
|
builder.add(Glob::new("*.tar.gz").unwrap());
|
||||||
builder.add(Glob::new("*.tar.xz").unwrap());
|
builder.add(Glob::new("*.tar.xz").unwrap());
|
||||||
builder.add(Glob::new("*.tar.bz2").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("*.tgz").unwrap());
|
||||||
builder.add(Glob::new("*.txz").unwrap());
|
builder.add(Glob::new("*.txz").unwrap());
|
||||||
builder.add(Glob::new("*.tbz2").unwrap());
|
builder.add(Glob::new("*.tbz2").unwrap());
|
||||||
|
BIN
tests/data/sherlock.lz4
Normal file
BIN
tests/data/sherlock.lz4
Normal file
Binary file not shown.
@ -1792,6 +1792,26 @@ be, to a very large extent, the result of luck. Sherlock Holmes
|
|||||||
assert_eq!(lines, expected);
|
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]
|
#[test]
|
||||||
fn compressed_lzma() {
|
fn compressed_lzma() {
|
||||||
if !cmd_exists("xz") {
|
if !cmd_exists("xz") {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user