From 2c8d05b9f877c95fc0e4be29328ef45509bc9e7f Mon Sep 17 00:00:00 2001 From: Nathan Fisher Date: Mon, 3 Jul 2023 19:04:55 -0400 Subject: [PATCH] Add `Kind` enum and method to get it's value from a u32 --- src/lib.rs | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 7326e73..03f9a19 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -288,9 +288,7 @@ impl FileType { match self { Self::Normal(f) => { writer.write_all(&[0])?; - writer.write_all(&f.len.to_le_bytes())?; - f.checksum.write(writer)?; - writer.write_all(&f.data)?; + f.write(writer)?; }, Self::HardLink(s) => { writer.write_all(&[1])?; @@ -319,6 +317,33 @@ impl FileType { } } +#[derive(Debug)] +enum Kind { + Normal, + Dir, + Char, + Block, + Pipe, +} + +impl From for Kind { + fn from(value: u32) -> Self { + if value & 0o60000 != 0 { + Self::Block + } else if value & 0o20000 != 0 { + Self::Char + } else if value & 0o10000 != 0 { + Self::Pipe + } else if value & 0o40000 != 0 { + Self::Dir + } else if value & 0o100000 != 0 { + Self::Normal + } else { + panic!(); + } + } +} + #[derive(Debug)] pub struct Node { pub name: String,