1#[derive(Debug, Copy, Clone, PartialEq)]
2pub enum EntryType {
3 File,
4 Directory,
5}
6
7#[derive(Debug, Clone, PartialEq)]
8pub struct Entry {
9 entry_type: EntryType,
10 content: Option<Vec<u8>>,
11}
12
13impl Entry {
14 pub fn new(entry_type: EntryType) -> Entry {
15 Entry {
16 entry_type,
17 content: None,
18 }
19 }
20
21 pub fn entry_type(&self) -> EntryType {
22 self.entry_type
23 }
24
25 pub fn is_file(&self) -> bool {
26 self.entry_type == EntryType::File
27 }
28
29 pub fn is_dir(&self) -> bool {
30 self.entry_type == EntryType::Directory
31 }
32
33 pub fn content(&self) -> Option<&Vec<u8>> {
34 self.content.as_ref()
35 }
36
37 pub fn set_content(&mut self, content: &[u8]) {
38 self.content = Some(Vec::from(content));
39 }
40
41 pub fn append_content(&mut self, content: &[u8]) {
42 let mut new_content = if self.content.is_some() {
43 self.content.take().unwrap()
44 } else {
45 Vec::new()
46 };
47 new_content.extend_from_slice(content);
48 self.set_content(&new_content);
49 }
50}