Lyric v3.9.0

std.io.file

text function

pub fn text(path: string): ?string

The whole content as text, decoded as UTF-8 — bytes that are not valid UTF-8 become U+FFFD. For binary data use bytes. null when the file does not exist or is not readable.

stdlib/std/io/file.lyr:44

bytes function

pub fn bytes(path: string): ?uint8[]

The raw bytes, undecoded — what text cannot give: its UTF-8 decoding turns invalid bytes into U+FFFD. null when the file is not readable; an EMPTY array is an empty file.

stdlib/std/io/file.lyr:48

lines function

pub fn lines(path: string): ?string[]

The lines of a file, terminators removed, so whether the file used CRLF or LF is no longer visible. null when the file is not readable; an EMPTY array is an empty file.

stdlib/std/io/file.lyr:52

writeText function

pub fn writeText(path: string, content: string): bool

Writes text (UTF-8), replacing an existing file. true on success.

stdlib/std/io/file.lyr:55

appendText function

pub fn appendText(path: string, content: string): bool

Appends to an existing file or creates it. true on success.

stdlib/std/io/file.lyr:58

exists function

pub fn exists(path: string): bool

Whether something — file or directory — exists at the path.

stdlib/std/io/file.lyr:61

remove function

pub fn remove(path: string): bool

true when the file is gone afterwards, including when it never existed.

stdlib/std/io/file.lyr:64

writeBytes function

pub fn writeBytes(path: string, data: uint8[]): bool

Writes raw bytes, replacing an existing file. true on success — the writeText convention. (v1.14: the first native whose parameter is an array.)

stdlib/std/io/file.lyr:68

appendBytes function

pub fn appendBytes(path: string, data: uint8[]): bool

Appends raw bytes to an existing file or creates it. true on success.

stdlib/std/io/file.lyr:71

textOrThrow function

pub fn textOrThrow(path: string): string throws IoError

text, with the reason when it cannot: the content, or an IoError saying why not.

stdlib/std/io/file.lyr:94

bytesOrThrow function

pub fn bytesOrThrow(path: string): uint8[] throws IoError

bytes, with the reason when it cannot.

stdlib/std/io/file.lyr:103

linesOrThrow function

pub fn linesOrThrow(path: string): string[] throws IoError

lines, with the reason when it cannot.

stdlib/std/io/file.lyr:112

sizeOrThrow function

pub fn sizeOrThrow(path: string): int throws IoError

size, with the reason when it cannot.

stdlib/std/io/file.lyr:121

entriesOrThrow function

pub fn entriesOrThrow(path: string): string[] throws IoError

entries, with the reason when it cannot.

stdlib/std/io/file.lyr:130

writeTextOrThrow function

pub fn writeTextOrThrow(path: string, content: string): void throws IoError

writeText, with the reason when it cannot.

stdlib/std/io/file.lyr:143

appendTextOrThrow function

pub fn appendTextOrThrow(path: string, content: string): void throws IoError

appendText, with the reason when it cannot.

stdlib/std/io/file.lyr:150

writeBytesOrThrow function

pub fn writeBytesOrThrow(path: string, data: uint8[]): void throws IoError

writeBytes, with the reason when it cannot.

stdlib/std/io/file.lyr:157

appendBytesOrThrow function

pub fn appendBytesOrThrow(path: string, data: uint8[]): void throws IoError

appendBytes, with the reason when it cannot.

stdlib/std/io/file.lyr:164

removeOrThrow function

pub fn removeOrThrow(path: string): void throws IoError

remove, with the reason when it cannot. A file that never existed is still success, as in remove — the twin throws exactly where the silent form answers false.

stdlib/std/io/file.lyr:172

copyOrThrow function

pub fn copyOrThrow(from: string, to: string): void throws IoError

copy, with the reason when it cannot.

stdlib/std/io/file.lyr:179

moveOrThrow function

pub fn moveOrThrow(from: string, to: string): void throws IoError

move, with the reason when it cannot.

stdlib/std/io/file.lyr:186

createDirOrThrow function

pub fn createDirOrThrow(path: string): void throws IoError

createDir, with the reason when it cannot.

stdlib/std/io/file.lyr:193

createDirAllOrThrow function

pub fn createDirAllOrThrow(path: string): void throws IoError

createDirAll, with the reason when it cannot.

stdlib/std/io/file.lyr:200

removeDirOrThrow function

pub fn removeDirOrThrow(path: string): void throws IoError

removeDir, with the reason when it cannot.

stdlib/std/io/file.lyr:207

size function

pub fn size(path: string): ?int

The size in bytes, or null when the file does not exist.

stdlib/std/io/file.lyr:218

isFile function

pub fn isFile(path: string): bool

Whether the path names an existing FILE.

stdlib/std/io/file.lyr:220

isDirectory function

pub fn isDirectory(path: string): bool

Whether the path names an existing DIRECTORY.

stdlib/std/io/file.lyr:222

copy function

pub fn copy(from: string, to: string): bool

Copies. false when the source is missing or the target is not writable.

stdlib/std/io/file.lyr:225

move function

pub fn move(from: string, to: string): bool

Moves or renames; the same operation on every file system.

stdlib/std/io/file.lyr:228

createDir function

pub fn createDir(path: string): bool

Creates one directory; the parent must exist. createDirAll creates the chain.

stdlib/std/io/file.lyr:231

createDirAll function

pub fn createDirAll(path: string): bool

Creates missing parent directories too. An existing directory counts as success.

stdlib/std/io/file.lyr:234

removeDir function

pub fn removeDir(path: string): bool

Deletes an EMPTY directory. There is no recursive delete; a caller that needs one writes the loop visibly.

stdlib/std/io/file.lyr:238

entries function

pub fn entries(path: string): ?string[]

The entries of a directory: names rather than paths, sorted alphabetically. null when the directory cannot be read; an EMPTY array is an empty directory — the 2.14 convention, which listDir predates.

stdlib/std/io/file.lyr:243

listDir function

pub fn listDir(path: string): string[]

The entries of a directory — names, sorted — before 3.7. It answers an empty array to both "empty" and "unreadable", which no caller can tell apart; entries says null, and entriesOrThrow says why.

stdlib/std/io/file.lyr:248

tempDir function

pub fn tempDir(): string

A path in the system's temporary directory. Does NOT create the file.

stdlib/std/io/file.lyr:252

joinPath function

pub fn joinPath(left: string, right: string): string

Joins two path parts, with neither a doubled nor a missing separator.

stdlib/std/io/file.lyr:266

fileName function

pub fn fileName(path: string): string

The last component. "a/b/c.txt" becomes "c.txt".

stdlib/std/io/file.lyr:299

parentDir function

pub fn parentDir(path: string): string

Everything before the last separator, or "" when there is none.

stdlib/std/io/file.lyr:305

extension function

pub fn extension(path: string): string

The extension WITHOUT the dot. "" when there is none.

A leading dot does not count: ".gitignore" has no extension, that is its name. This rule differs between languages, so it is stated here.

stdlib/std/io/file.lyr:321

stem function

pub fn stem(path: string): string

The name without its extension. "a/b/c.txt" becomes "c".

stdlib/std/io/file.lyr:337

withExtension function

pub fn withExtension(path: string, ext: string): string

Replaces the extension. An empty extension removes it.

stdlib/std/io/file.lyr:347

isAbsolute function

pub fn isAbsolute(path: string): bool

Does the path start at the root? Recognises /x and C:\x.

stdlib/std/io/file.lyr:355