Skip to main content

zipatch_rs/chunk/
adir.rs

1use binrw::BinRead;
2
3use super::util::read_null_trimmed_utf8;
4
5/// `ADIR` chunk: create a directory under the game install root.
6#[derive(BinRead, Debug, Clone, PartialEq, Eq)]
7#[br(big)]
8pub struct AddDirectory {
9    /// Directory path relative to the game install root.
10    #[br(parse_with = read_null_trimmed_utf8)]
11    pub name: String,
12}
13
14pub(crate) fn parse(body: &[u8]) -> crate::Result<AddDirectory> {
15    super::util::parse_be(body)
16}
17
18#[cfg(test)]
19mod tests {
20    use super::parse;
21
22    #[test]
23    fn parses_add_directory() {
24        let mut body = Vec::new();
25        body.extend_from_slice(&5u32.to_be_bytes());
26        body.extend_from_slice(b"sqex\0");
27        assert_eq!(parse(&body).unwrap().name, "sqex");
28    }
29
30    #[test]
31    fn null_padding_trimmed() {
32        let mut body = Vec::new();
33        body.extend_from_slice(&8u32.to_be_bytes());
34        body.extend_from_slice(b"ex\0\0\0\0\0\0");
35        assert_eq!(parse(&body).unwrap().name, "ex");
36    }
37}