Skip to main content

spreadsheet_ods/
manifest.rs

1//! The manifest for all files contained in the zip.
2//!
3//! For unprocessed zip entries this also contains the actual bytes.
4
5use get_size2::GetSize;
6
7/// A manifest entry.
8#[derive(Debug, Clone, GetSize)]
9pub struct Manifest {
10    /// Path in the zip
11    pub full_path: String,
12    /// Version. Only used for the root entry "/".
13    pub version: Option<String>,
14    /// Mediatype.
15    pub media_type: String,
16    /// Unprocessed data is stored here.
17    /// Everything except styles.xml, meta.xml, content.xml and settings.xml
18    pub buffer: Option<Vec<u8>>,
19}
20
21impl Default for Manifest {
22    fn default() -> Self {
23        Self {
24            full_path: "".to_string(),
25            version: None,
26            media_type: "".to_string(),
27            buffer: None,
28        }
29    }
30}
31
32impl Manifest {
33    /// Standard manifest entry without data.
34    pub fn new<S: Into<String>, T: Into<String>>(full_path: S, media_type: T) -> Self {
35        Self {
36            full_path: full_path.into(),
37            version: None,
38            media_type: media_type.into(),
39            buffer: None,
40        }
41    }
42
43    /// Manifest entry with data.
44    pub fn with_buf<S: Into<String>, T: Into<String>>(
45        full_path: S,
46        media_type: T,
47        buf: Vec<u8>,
48    ) -> Self {
49        Self {
50            full_path: full_path.into(),
51            version: None,
52            media_type: media_type.into(),
53            buffer: Some(buf),
54        }
55    }
56
57    /// Name ends with "/"
58    pub fn is_dir(&self) -> bool {
59        self.full_path.ends_with('/')
60    }
61}