mod dir;
mod dir_entry;
mod file;
mod read_dir;
pub use dir::*;
pub use dir_entry::*;
pub use file::*;
pub use read_dir::*;
pub use crate::fs::{DirBuilder, FileType, Metadata, OpenOptions, Permissions};
fn from_utf8<P: AsRef<str>>(path: P) -> std::io::Result<std::path::PathBuf> {
let string = arf_strings::PosixString::from_path_str(path.as_ref())
.map_err(|_| std::io::Error::new(std::io::ErrorKind::InvalidData, "invalid path string"))?;
#[cfg(any(unix, target_os = "redox", target_os = "wasi"))]
let path = {
use std::{ffi::OsStr, os::unix::ffi::OsStrExt};
let bytes = string.as_cstr().to_bytes();
OsStr::from_bytes(bytes).to_owned()
};
#[cfg(windows)]
let path = {
use std::{ffi::OsString, os::windows::ffi::OsStringExt};
let utf8 = string.as_cstr().to_str().map_err(|_| {
std::io::Error::new(std::io::ErrorKind::InvalidData, "invalid path string")
})?;
let utf16: Vec<_> = utf8.encode_utf16().collect();
OsString::from_wide(&utf16)
};
Ok(path.into())
}
fn to_utf8<P: AsRef<std::path::Path>>(path: P) -> std::io::Result<String> {
let osstr = path.as_ref().as_os_str();
#[cfg(any(unix, target_os = "redox", target_os = "wasi"))]
let cstr = {
use std::{ffi::CString, os::unix::ffi::OsStrExt};
CString::new(osstr.as_bytes())?
};
#[cfg(windows)]
let cstr = {
use std::{ffi::CString, os::windows::ffi::OsStrExt};
let utf16: Vec<_> = osstr.encode_wide().collect();
let str = String::from_utf16(&utf16).map_err(|_| {
std::io::Error::new(std::io::ErrorKind::InvalidData, "invalid path string")
})?;
CString::new(str)?
};
Ok(arf_strings::WasiString::from_maybe_nonutf8_cstr(&cstr)
.as_str()
.to_owned())
}