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 FileInfo

Owned metadata snapshot. Permissions are POSIX mode bits (07777). * modifiedNanoseconds is signed Unix time; unrepresentable times throw. * name is the supplied path for stat, or the basename for listEntries.

Fields

nameString
kindString
sizeInt64
modifiedNanosecondsInt64
permissionsInt64

fn fsMetadataChecked(path: String, listing: Int64) → List<String>

fn fsRenameChecked(from: String, to: String) → String

fn fsRemoveDirectoryChecked(path: String, recursive: Int64) → String

fn fsRealPathChecked(path: String) → List<String>

fn fsHomeDirectoryChecked() → List<String>

fn fsReadTextOutcome(path: String) → List<String>

fn fsWriteTextOutcome(path: String, text: String, append: Int64) → List<String>

fn fsCopyOutcome(from: String, to: String) → List<String>

fn fsMutateOutcome(from: String, to: String, move: Int64) → List<String>

class Fs

Methods

fn tryReadFile(path: String) → IoResult<String>
fn mutationResult(data: List<String>) → IoResult<Bool>
fn tryWriteFile(path: String, text: String) → IoResult<Bool>
fn tryAppendFile(path: String, text: String) → IoResult<Bool>
fn tryCopyFile(from: String, to: String) → IoResult<Bool>
fn tryMoveFile(from: String, to: String) → IoResult<Bool>
fn tryDeleteFile(path: String) → IoResult<Bool>
fn readFile(path: String) → String
@Throwsfn writeFile(path: String, content: String) → Nothing
fn appendFile(path: String, content: String) → Nothing
fn deleteFile(path: String) → Nothing
@Throwsfn copyFile(src: String, dest: String) → Nothing
@Throwsfn moveFile(src: String, dest: String) → Nothing
fn listDirectory(path: String) → List<String>
@Throwsfn createDirectory(path: String) → Nothing
@Throwsfn createDirectories(path: String) → Nothing
@Throwsfn deleteDirectory(path: String) → Nothing
@Throwsfn stat(path: String) → FileInfo?
fn decodeInfo(data: List<String>, offset: Int64) → FileInfo
fn isDirectory(path: String) → Bool
fn isFile(path: String) → Bool
fn isSymlink(path: String) → Bool
@Throwsfn listEntries(path: String) → List<FileInfo>
@Throwsfn rename(from: String, to: String) → Nothing
@Throwsfn deleteDirectoryRecursive(path: String) → Nothing
@Throwsfn realPath(path: String) → String
@Throwsfn homeDirectory() → String

@Errorclass IoError

* A file-system operation failed; `message` carries the operating system's reason.

Fields

messageString

class IoFailure

Fields

codeInt64
operationString
targetString
causeString

Methods

fn message() → String

class IoResult<T>

Fields

valuesList<T>
failuresList<IoFailure>

Methods

fn ok(value: T) → IoResult<T>
fn fail(data: List<String>) → IoResult<T>
fn isOk() → Bool
fn isErr() → Bool
fn unwrap() → T
fn failure() → IoFailure

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

@Throwsfn 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.
@Throwsfn 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.