1mod dir;
4mod file;
5
6pub use self::dir::{DirBuilder, DirEntry, ReadDir};
7pub use self::file::{File, FileType, Metadata, OpenOptions, Permissions};
8
9use alloc::{string::String, vec::Vec};
10use axio::{self as io, prelude::*};
11
12pub fn read_dir(path: &str) -> io::Result<ReadDir<'_>> {
14    ReadDir::new(path)
15}
16
17pub fn canonicalize(path: &str) -> io::Result<String> {
20    crate::root::absolute_path(path)
21}
22
23pub fn current_dir() -> io::Result<String> {
25    crate::root::current_dir()
26}
27
28pub fn set_current_dir(path: &str) -> io::Result<()> {
30    crate::root::set_current_dir(path)
31}
32
33pub fn read(path: &str) -> io::Result<Vec<u8>> {
35    let mut file = File::open(path)?;
36    let size = file.metadata().map(|m| m.len()).unwrap_or(0);
37    let mut bytes = Vec::with_capacity(size as usize);
38    file.read_to_end(&mut bytes)?;
39    Ok(bytes)
40}
41
42pub fn read_to_string(path: &str) -> io::Result<String> {
44    let mut file = File::open(path)?;
45    let size = file.metadata().map(|m| m.len()).unwrap_or(0);
46    let mut string = String::with_capacity(size as usize);
47    file.read_to_string(&mut string)?;
48    Ok(string)
49}
50
51pub fn write<C: AsRef<[u8]>>(path: &str, contents: C) -> io::Result<()> {
53    File::create(path)?.write_all(contents.as_ref())
54}
55
56pub fn metadata(path: &str) -> io::Result<Metadata> {
59    File::open(path)?.metadata()
60}
61
62pub fn create_dir(path: &str) -> io::Result<()> {
64    DirBuilder::new().create(path)
65}
66
67pub fn create_dir_all(path: &str) -> io::Result<()> {
70    DirBuilder::new().recursive(true).create(path)
71}
72
73pub fn remove_dir(path: &str) -> io::Result<()> {
75    crate::root::remove_dir(None, path)
76}
77
78pub fn remove_file(path: &str) -> io::Result<()> {
80    crate::root::remove_file(None, path)
81}
82
83pub fn rename(old: &str, new: &str) -> io::Result<()> {
88    crate::root::rename(old, new)
89}