diff --git a/src/archive/zip.rs b/src/archive/zip.rs index d4a6de8..0cd6031 100644 --- a/src/archive/zip.rs +++ b/src/archive/zip.rs @@ -170,25 +170,3 @@ fn __unix_set_permissions(file_path: &Path, file: &ZipFile) -> crate::Result<()> Ok(()) } - -mod utf8 { - use std::path::{Path, PathBuf}; - - fn is_invalid_utf8(path: &Path) -> bool { - #[cfg(unix)] - { - use std::{os::unix::prelude::OsStrExt, str}; - - let bytes = path.as_os_str().as_bytes(); - str::from_utf8(bytes).is_err() - } - #[cfg(not(unix))] - { - path.to_str().is_none() - } - } - - pub fn get_invalid_utf8_paths(paths: &[PathBuf]) -> Vec { - paths.iter().filter_map(|path| is_invalid_utf8(&path).then(|| path.clone())).collect() - } -} diff --git a/src/utils/mod.rs b/src/utils/mod.rs index 1558478..3d0001b 100644 --- a/src/utils/mod.rs +++ b/src/utils/mod.rs @@ -13,3 +13,26 @@ pub use fs::{cd_into_same_dir_as, create_dir_if_non_existent, dir_is_empty, try_ pub use question::{ create_or_ask_overwrite, user_wants_to_continue_decompressing, user_wants_to_overwrite, QuestionPolicy, }; +pub use utf8::{get_invalid_utf8_paths, is_invalid_utf8}; + +mod utf8 { + use std::path::{Path, PathBuf}; + + pub fn is_invalid_utf8(path: &Path) -> bool { + #[cfg(unix)] + { + use std::{os::unix::prelude::OsStrExt, str}; + + let bytes = path.as_os_str().as_bytes(); + str::from_utf8(bytes).is_err() + } + #[cfg(not(unix))] + { + path.to_str().is_none() + } + } + + pub fn get_invalid_utf8_paths(paths: &[PathBuf]) -> Vec { + paths.iter().filter_map(|path| is_invalid_utf8(&path).then(|| path.clone())).collect() + } +}