SplitScript reference / File
File
type
File
Provides whole-file, read-only filesystem operations.
These associated functions open, consume, and close a file within one call; no file handle escapes into SplitScript. The WASI filesystem is otherwise almost empty; the host filesystem is currently mounted read-only below /mnt. Paths must be absolute because there is no portable current directory. Other absolute roots may be exposed by the runtime in the future.
On Windows, C:\foo\bar.txt becomes /mnt/c/foo/bar.txt (and likewise for other drive letters). On Linux or macOS, /foo/bar.txt becomes /mnt/foo/bar.txt.
Process.path and Module.path already return this portable spelling.
Examples
Read a selected data file
let bytes = File.readAllBytes("/mnt/c/Games/example/data.bin")?
print(`Loaded {bytes.length()} bytes`)
Methods
| Member | Description | Available through |
|---|---|---|
| readAllBytes | Reads an entire file as raw bytes. | |
| readAllText | Reads an entire UTF-8 text file. |