A collection of utilities for working with the local filesystem.
|String| -> File
Returns an empty File
at the provided path.
If the file already exists it will be truncated.
A runtime error will be thrown if the file can't be created.
f = io.create "foo.temp"
f.write_line "Hello"
f.read_to_string()
# Hello
|| -> String
Returns the current working directory as a String, or Null if the current directory can't be retrieved.
|String| -> Bool
Returns true if a file exists at the provided path.
path = "foo.temp"
io.exists path
# false
io.create path
io.exists path
# true
|String, Value...| -> String
Takes an initial path as a string, and extends it with the provided nodes, inserting a platform-appropriate separator between each node.
# On Windows
io.extend_path ".", "foo", "bar", "baz.txt"
# .\foo\bar\baz.txt
# On Linux
io.extend_path ".", "foo", "bar", "baz.txt"
# ./foo/bar/baz.txt
|String| -> File
Opens the file at the given path, and returns a corresponding File
.
An error is thrown if a file can't be opened at the given path.
f = io.open "path/to/existing.file"
f.exists()
# true
```kototype
|Value| -> Null
Prints a single value to the active output.
|Value, Value...| -> Null
Prints a series of values to the active output as a tuple.
string.format
.print
depends on the configuration of the runtime.
The default output is stdout
.|String| -> String
Returns a string containing the contents of the file at the given path.
Errors are thrown:
f = io.create "foo.temp"
f.write_line "Hello!"
io.read_to_string "foo.temp"
# Hello!
|String| -> Null
Removes the file at the given path.
path = "foo.temp"
io.create path
io.exists path
# true
io.remove_file path
io.exists path
# false
|| -> File
Returns the standard error output of the current process as a file.
io.stderr().write_line "An error occurred!"
|| -> File
Returns the standard input of the current process as a file.
io.stdin().read_to_string()
# "..."
|| -> File
Returns the standard output of the current process as a file.
io.stdout().write_line "Hello, World!"
|| -> String
Returns the path to a temporary directory.
This defers to Rust's std::env::temp_dir
, for details see
its documentation.
A map that wraps a file handle, returned from functions in io
.
|File| -> Null
Ensures that any buffered changes to the file have been written.
|File| -> String
Returns the file's path.
|File| -> String or Null
Reads a line of output from the file as a string, not including the newline.
When the end of the file is reached, Null will be returned.
An error is thrown if the line doesn't contain valid UTF-8 data.
|File| -> String
Reads the file's contents to a string.
An error is thrown if the file doesn't contain valid UTF-8 data.
|File, Number| -> Null
Seeks within the file to the specified position in bytes.
|File, Value| -> Null
Writes the formatted value as a string to the file.
|File, Value| -> Null
Writes the formatted value as a string, with a newline, to the file.