mod dir;
mod file;
pub mod port;
pub use self::dir::{DirBuilder, DirEntry, ReadDir};
pub use self::file::{File, FileType, Metadata, OpenOptions, Permissions};
use axerrno::AxResult;
use axfs_vfs::VfsNodeRef;
pub use axio::{Read, Seek, SeekFrom, Write};
pub use port::*;
use alloc::{string::String, vec::Vec};
#[allow(unused_imports)]
use axio::{self as io, prelude::*};
pub fn read_dir(path: &str) -> io::Result<ReadDir> {
ReadDir::new(path)
}
pub fn canonicalize(path: &str) -> io::Result<String> {
crate::root::absolute_path(path)
}
pub fn current_dir() -> io::Result<String> {
crate::root::current_dir()
}
pub fn set_current_dir(path: &str) -> io::Result<()> {
crate::root::set_current_dir(path)
}
pub fn read(path: &str) -> io::Result<Vec<u8>> {
let mut file = File::open(path)?;
let size = file.metadata().map(|m| m.len()).unwrap_or(0);
let mut bytes = Vec::with_capacity(size as usize);
file.read_to_end(&mut bytes)?;
Ok(bytes)
}
pub fn read_to_string(path: &str) -> io::Result<String> {
let mut file = File::open(path)?;
let size = file.metadata().map(|m| m.len()).unwrap_or(0);
let mut string = String::with_capacity(size as usize);
file.read_to_string(&mut string)?;
Ok(string)
}
pub fn write<C: AsRef<[u8]>>(path: &str, contents: C) -> io::Result<()> {
File::create(path)?.write_all(contents.as_ref())
}
pub fn metadata(path: &str) -> io::Result<Metadata> {
File::open(path)?.metadata()
}
pub fn create_dir(path: &str) -> io::Result<()> {
DirBuilder::new().create(path)
}
pub fn create_dir_all(path: &str) -> io::Result<()> {
DirBuilder::new().recursive(true).create(path)
}
pub fn remove_dir(path: &str) -> io::Result<()> {
crate::root::remove_dir(None, path)
}
pub fn remove_file(path: &str) -> io::Result<()> {
crate::root::remove_file(None, path)
}
pub fn rename(old: &str, new: &str) -> io::Result<()> {
crate::root::rename(old, new)
}
pub fn path_exists(path: &str) -> bool {
crate::root::lookup(None, path).is_ok()
}
pub fn lookup(path: &str) -> AxResult<VfsNodeRef> {
crate::root::lookup(None, path)
}