1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
mod bounded;
mod extension;

pub use extension::*;

pub use self::bounded::BoundedFileOption;
pub use self::bounded::BoundedFileSink;
pub use self::bounded::BoundedFileSinkError;

#[cfg(feature = "mmap")]
pub mod mmap;

pub use async_fs::*;

pub mod util {

    use std::io::Error as IoError;
    use std::path::Path;

    use super::File;
    use super::OpenOptions;

    /// open for write only
    pub async fn create<P>(path: P) -> Result<File, IoError>
    where
        P: AsRef<Path>,
    {
        File::create(path.as_ref()).await
    }

    /// open for only read
    pub async fn open<P>(path: P) -> Result<File, IoError>
    where
        P: AsRef<Path>,
    {
        let file_path = path.as_ref();
        File::open(file_path).await
    }

    /// open for read and write
    pub async fn open_read_write<P>(path: P) -> Result<File, IoError>
    where
        P: AsRef<Path>,
    {
        let file_path = path.as_ref();
        let mut option = OpenOptions::new();
        option.read(true).write(true).create(true).append(false);

        option.open(file_path).await
    }

    pub async fn open_read_append<P>(path: P) -> Result<File, IoError>
    where
        P: AsRef<Path>,
    {
        let file_path = path.as_ref();
        let mut option = OpenOptions::new();
        option.read(true).create(true).append(true);

        option.open(file_path).await
    }
}