From 7305f0caeb2e2641e859e2ef9478a732fb40c9fc Mon Sep 17 00:00:00 2001 From: Mykyta Onipchenko <44075969+nenikitov@users.noreply.github.com> Date: Sun, 12 Nov 2023 21:53:15 -0500 Subject: [PATCH] feat: implement `new` for `PackFile` refactor: EntryKind enum was removed. --- lib/src/packfile/mod.rs | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/lib/src/packfile/mod.rs b/lib/src/packfile/mod.rs index f5a6ee9..30e8adf 100644 --- a/lib/src/packfile/mod.rs +++ b/lib/src/packfile/mod.rs @@ -7,12 +7,6 @@ use flate2::read::ZlibDecoder; use nom::*; use std::io::Read; -#[derive(Debug, PartialEq)] -enum EntryKind { - // TODO(nenikitov): Add more kinds - Unknown, -} - #[derive(Debug, PartialEq)] struct EntryHeader { offset: u32, @@ -22,7 +16,6 @@ struct EntryHeader { #[derive(Debug, PartialEq)] pub struct EntryData { bytes: Vec, - kind: EntryKind, } #[derive(Debug, PartialEq)] @@ -36,7 +29,14 @@ impl PackFile { const COPYRIGHT_LENGTH: usize = 56; pub fn new(input: &[u8]) -> Result { - todo!() + let (copyright, entries) = { + let (input, (copyright, total_entries)) = Self::header(input)?; + let (input, (headers)) = Self::entry_headers(input, total_entries)?; + (copyright, headers) + }; + let (input, entries) = Self::entries(input, &entries)?; + + Ok((input, Self { copyright, entries })) } fn header(input: &[u8]) -> Result<(String, u32)> { @@ -92,10 +92,7 @@ impl PackFile { bytes.to_vec() }; - EntryData { - bytes, - kind: EntryKind::Unknown, - } + EntryData { bytes } } let entries = entry_headers.iter().map(|h| entry(input, h)).collect(); @@ -181,11 +178,9 @@ mod tests { [ EntryData { bytes: b"Ashen".to_vec(), - kind: EntryKind::Unknown }, EntryData { bytes: b"Ashen\n".to_vec(), - kind: EntryKind::Unknown } ] );