forked from nulang-org/nulang
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfs.nula
More file actions
31 lines (27 loc) · 1.1 KB
/
Copy pathfs.nula
File metadata and controls
31 lines (27 loc) · 1.1 KB
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
// Nulang standard library — filesystem I/O via built-in FS effect.
// Import: `import std.fs`
//
// The `FS` effect is wired into the standalone VM.
// Operations: `perform FS.read(path)`, `perform FS.write(path, content)`,
// `perform FS.append(path, content)`, `perform FS.exists(path)`.
/// Read the entire contents of a file into a string.
/// Returns nil if the file cannot be read (missing, permission denied, etc.).
pub fn read(path: String) -> String ! {FS} {
perform FS.read(path)
}
/// Write a string to a file, overwriting any existing content.
/// Creates the file if it does not exist.
/// Returns nil if the file cannot be written.
pub fn write(path: String, content: String) -> Unit ! {FS} {
perform FS.write(path, content)
}
/// Append a string to the end of a file.
/// Creates the file if it does not exist.
/// Returns nil if the file cannot be written.
pub fn append(path: String, content: String) -> Unit ! {FS} {
perform FS.append(path, content)
}
/// Check whether a file or directory exists at the given path.
pub fn exists(path: String) -> Bool ! {FS} {
perform FS.exists(path)
}