1mod dir;
18mod file;
19
20use alloc::{string::String, vec::Vec};
21
22use ax_io::{self as io, prelude::*};
23
24pub use self::{
25 dir::{DirBuilder, DirEntry, ReadDir},
26 file::{File, FileType, Metadata, OpenOptions, Permissions},
27};
28
29pub fn read_dir(path: &str) -> io::Result<ReadDir<'_>> {
31 ReadDir::new(path)
32}
33
34pub fn canonicalize(path: &str) -> io::Result<String> {
37 crate::root::absolute_path(path)
38}
39
40pub fn current_dir() -> io::Result<String> {
42 crate::root::current_dir()
43}
44
45pub fn set_current_dir(path: &str) -> io::Result<()> {
47 crate::root::set_current_dir(path)
48}
49
50pub fn read(path: &str) -> io::Result<Vec<u8>> {
52 let mut file = File::open(path)?;
53 let size = file.metadata().map(|m| m.len()).unwrap_or(0);
54 let mut bytes = Vec::with_capacity(size as usize);
55 file.read_to_end(&mut bytes)?;
56 Ok(bytes)
57}
58
59pub fn read_to_string(path: &str) -> io::Result<String> {
61 let mut file = File::open(path)?;
62 let size = file.metadata().map(|m| m.len()).unwrap_or(0);
63 let mut string = String::with_capacity(size as usize);
64 file.read_to_string(&mut string)?;
65 Ok(string)
66}
67
68pub fn write<C: AsRef<[u8]>>(path: &str, contents: C) -> io::Result<()> {
70 File::create(path)?.write_all(contents.as_ref())
71}
72
73pub fn metadata(path: &str) -> io::Result<Metadata> {
76 File::open(path)?.metadata()
77}
78
79pub fn create_dir(path: &str) -> io::Result<()> {
81 DirBuilder::new().create(path)
82}
83
84pub fn create_dir_all(path: &str) -> io::Result<()> {
87 DirBuilder::new().recursive(true).create(path)
88}
89
90pub fn remove_dir(path: &str) -> io::Result<()> {
92 crate::root::remove_dir(None, path)
93}
94
95pub fn remove_file(path: &str) -> io::Result<()> {
97 crate::root::remove_file(None, path)
98}
99
100pub fn rename(old: &str, new: &str) -> io::Result<()> {
105 crate::root::rename(old, new)
106}