Skip to content

Commit

Permalink
feat: implement new for PackFile
Browse files Browse the repository at this point in the history
refactor: EntryKind enum was removed.
  • Loading branch information
nenikitov authored Nov 13, 2023
1 parent 48da2aa commit 7305f0c
Showing 1 changed file with 9 additions and 14 deletions.
23 changes: 9 additions & 14 deletions lib/src/packfile/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -22,7 +16,6 @@ struct EntryHeader {
#[derive(Debug, PartialEq)]
pub struct EntryData {
bytes: Vec<u8>,
kind: EntryKind,
}

#[derive(Debug, PartialEq)]
Expand All @@ -36,7 +29,14 @@ impl PackFile {
const COPYRIGHT_LENGTH: usize = 56;

pub fn new(input: &[u8]) -> Result<Self> {
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)> {
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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
}
]
);
Expand Down

0 comments on commit 7305f0c

Please sign in to comment.