diff --git a/src/virtual_fs.rs b/src/virtual_fs.rs index a9672c0..cc0189c 100644 --- a/src/virtual_fs.rs +++ b/src/virtual_fs.rs @@ -1,4 +1,4 @@ -use std::collections::HashMap; +use std::{collections::HashMap, fs, io, path::Path}; #[derive(Debug, Default, Clone)] pub struct VFolder { @@ -102,6 +102,24 @@ impl VFolder { self.files.get_mut(name) } } + + pub fn place(&self, path: &Path) -> io::Result<()> { + fs::create_dir_all(path)?; + for (name, folder) in &self.folders { + folder.place(&path.join(name))?; + } + for (name, file) in &self.files { + match file { + VFile::Text(text) => { + fs::write(path.join(name), text)?; + } + VFile::Binary(data) => { + fs::write(path.join(name), data)?; + } + } + } + Ok(()) + } } #[derive(Debug, Clone)]