diff --git a/Cargo.toml b/Cargo.toml index dbdda79..e639ba7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,7 +15,7 @@ license = "MIT" name="tar" [dependencies] -nom = { default-features = false, features = ["alloc"], git = "https://github.com/Geal/nom.git", rev = "ef5e0bbc" } +nom = { default-features = false, git = "https://github.com/Geal/nom.git", rev = "ef5e0bbc" } [badges] travis-ci = { repository = "Keruspe/tar-parser.rs" } diff --git a/src/parser.rs b/src/parser.rs index 72a6f70..ff5483c 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -4,7 +4,7 @@ use nom::bytes::complete::{tag, take, take_until}; use nom::character::complete::{oct_digit0, space0}; use nom::combinator::{all_consuming, map, map_parser, map_res, opt}; use nom::error::ErrorKind; -use nom::multi::many0; +use nom::multi::fold_many0; use nom::sequence::{pair, terminated}; /* @@ -375,13 +375,14 @@ fn parse_entry(i: &[u8]) -> IResult<&[u8], TarEntry<'_>> { * Tar archive parsing */ -fn filter_entries(entries: Vec>) -> Vec> { - /* Filter out empty entries */ - entries.into_iter().filter(|e| !e.header.name.is_empty()).collect() -} - pub fn parse_tar(i: &[u8]) -> IResult<&[u8], Vec>> { - all_consuming(map(many0(parse_entry), filter_entries))(i) + let entries = fold_many0(parse_entry, Vec::new, |mut vec, e| { + if !e.header.name.is_empty() { + vec.push(e) + } + vec + }); + all_consuming(entries)(i) } /*