Detect format from a path.
(path: &Path)
| 178 | |
| 179 | /// Detect format from a path. |
| 180 | pub fn from_path(path: &Path) -> Option<Self> { |
| 181 | let path_str = path.to_string_lossy().to_lowercase(); |
| 182 | |
| 183 | if path_str.ends_with(".tar.gz") || path_str.ends_with(".tgz") { |
| 184 | Some(Self::TarGz) |
| 185 | } else if path_str.ends_with(".tar") { |
| 186 | Some(Self::Tar) |
| 187 | } else if path_str.ends_with(".zip") { |
| 188 | Some(Self::Zip) |
| 189 | } else if path.is_dir() || !path.to_string_lossy().contains('.') { |
| 190 | Some(Self::Directory) |
| 191 | } else { |
| 192 | None |
| 193 | } |
| 194 | } |
| 195 | |
| 196 | /// Check if this format requires compression. |
| 197 | pub fn is_compressed(&self) -> bool { |