Create directories and extract all files to real filesystem. Creates parent directories of `path` if they do not already exist. Fails if some files already exist. In case of error, partially extracted directory may remain on the filesystem.
(&self, base_path: S)
| 75 | /// Fails if some files already exist. |
| 76 | /// In case of error, partially extracted directory may remain on the filesystem. |
| 77 | pub fn extract<S: AsRef<Path>>(&self, base_path: S) -> std::io::Result<()> { |
| 78 | let base_path = base_path.as_ref(); |
| 79 | |
| 80 | for entry in self.entries() { |
| 81 | let path = base_path.join(entry.path()); |
| 82 | |
| 83 | match entry { |
| 84 | DirEntry::Dir(d) => { |
| 85 | fs::create_dir_all(&path)?; |
| 86 | d.extract(base_path)?; |
| 87 | } |
| 88 | DirEntry::File(f) => { |
| 89 | fs::write(path, f.contents())?; |
| 90 | } |
| 91 | } |
| 92 | } |
| 93 | |
| 94 | Ok(()) |
| 95 | } |
| 96 | } |