fs

Generated by tinox doc

tinox.core.fs, bundled with the compiler and also available as a standalone tinox-central package.

Read write file

import tinox.core.fs
class Main
{
    fnc main() -> Int32
    {
        Fs::writeFile("/tmp/greeting.txt", "hello from tinox\n")
        Fs::appendFile("/tmp/greeting.txt", "second line\n")
        const content: String = Fs::readFile("/tmp/greeting.txt")
        println(content)
        Fs::copyFile("/tmp/greeting.txt", "/tmp/greeting-copy.txt")
        const files: List<String> = Fs::listDirectory("/tmp")
        println("entries: " + files.len().toString())
        Fs::deleteFile("/tmp/greeting-copy.txt")
        return 0
    }
}

class Fs

Methods

fn readFile(path: String) → String
fn writeFile(path: String, content: String) → Nothing
fn appendFile(path: String, content: String) → Nothing
fn deleteFile(path: String) → Nothing
fn copyFile(src: String, dest: String) → Nothing
fn moveFile(src: String, dest: String) → Nothing
fn listDirectory(path: String) → List<String>
fn createDirectory(path: String) → Nothing
fn createDirectories(path: String) → Nothing
fn deleteDirectory(path: String) → Nothing

class WatchEvent

* One file-system change reported by a Watcher. * * kind is one of "created", "modified", "deleted", "moved" or "overflow". * An "overflow" event (empty path) means the kernel dropped events: treat * every watched tree as changed and rescan it. For "moved", path is the * new location and oldPath the previous one; a path moved into or out of * the watched tree is reported as "created" or "deleted" instead.

Fields

kindString
pathString
oldPathString
isDirectoryBool

fn watchCreate() → Int64

fn watchLastError() → String

fn watchAdd(handle: Int64, path: String, recursive: Bool) → String

fn watchRemove(handle: Int64, path: String) → Nothing

fn watchPoll(handle: Int64, timeoutMs: Int64, debounceMs: Int64) → List<String>

fn watchClose(handle: Int64) → Nothing

class Watcher

* Watches files and directories for changes (Linux inotify). Typical * use is one task looping on poll(): * * const w = Watcher::create(50) * Watcher::watch(w, "/path/to/project", true) * while (running) { * for (e in Watcher::poll(w, 1000)) { ... } * } * Watcher::close(w) * * Recursive watches follow directories created later. Operations on one * Watcher are serialised; poll() blocks only its own caller. Watches * count against the kernel's fs.inotify.max_user_watches; hitting that * limit is reported as an error from watch(), never silently ignored.

Fields

handleInt64
debounceMsInt64

Methods

fn create(debounceMs: Int64) → Watcher
* debounceMs > 0 makes poll() keep collecting after the first event * until the stream has been quiet for that long (at most one extra * second), so a burst such as a git checkout arrives as one batch. * Identical events within a batch are reported once.
fn watch(w: Watcher, path: String, recursive: Bool) → Nothing
Watches path (a file or a directory); recursive also covers every sub-directory. Throws a String if path cannot be watched.
fn unwatch(w: Watcher, path: String) → Nothing
Stops watching path and, if it is a directory, everything below it.
fn poll(w: Watcher, timeoutMs: Int64) → List<WatchEvent>
* Waits up to timeoutMs (< 0 forever, 0 polls) for changes and returns * them in order; an empty list means timeout. See WatchEvent for the * event kinds, including the "overflow" rescan signal.
fn close(w: Watcher) → Nothing
Releases the inotify instance. Further use of the Watcher is a runtime error.