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

feat: implement new for creating packfile and remove entry kind #9

Merged
merged 1 commit into from
Nov 13, 2023
Merged
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
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
Loading