Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add support for lz4 decoding #898

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ addons:
- zsh
# Needed for testing decompression search.
- xz-utils
- liblz4-tool
matrix:
fast_finish: true
include:
Expand Down
2 changes: 1 addition & 1 deletion FAQ.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.)
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions ignore/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,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",
Expand Down
2 changes: 1 addition & 1 deletion src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1436,7 +1436,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
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we sort this list alphabetically, just like it is in FAQ.md?

(Sorry for being so OCD!)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I kept the original ordering because it seemed to be by popularity

supported. This option expects the decompression binaries to be available in
your PATH.

Expand Down
3 changes: 3 additions & 0 deletions src/decompressor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand All @@ -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()
};
Expand All @@ -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());
Expand Down
Binary file added tests/data/sherlock.lz4
Binary file not shown.
20 changes: 20 additions & 0 deletions tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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") {
Expand Down