Skip to content
FutureBlitz

    Install

    Import std.io.file

    std.io.file

    std.io's files, a call at a time: reading and writing a whole file's bytes, text, or lines, adding to one, writing one atomically, what's at a path, and copying, moving, and deleting. Each has an Async twin, which libuv's thread pool does while the main thread goes on, and whose Await resumes there. A file that can't be used throws an IOError whose Kind says why. Open and Create give a FileStream, for reading and writing a file a part at a time.

    std/io/file.fb

    Types

    FileKind enum

    Public Enum FileKind

    What's at a path.

    std/io/file.fb, line 53

    • FILE enum member #

      A file.

    • DIRECTORY enum member #

      A folder.

    • OTHER enum member #

      Something else, like a device or a pipe.

    LineEnding enum

    Public Enum LineEnding

    What ends each line a file's lines are written with.

    std/io/file.fb, line 65

    • LF enum member #

      "\n", as on every OS unless asked.

    • CRLF enum member #

      "\r\n", as some Windows programs want.

    Metadata struct

    Public Struct Metadata

    What's at a path, as File.Metadata found it: when it was last changed and read, and when it was made, which is Null where the OS or the disk doesn't say. IsReadOnly is whether its owner may not write it.

    std/io/file.fb, line 75

    • Public ReadOnly Field Kind: FileKind field #

      Whether it's a file, a folder, or a link.

    • Public ReadOnly Field Size: Int64 field #

      How many bytes it holds.

    • Public ReadOnly Field Modified: Timestamp field #

      When it was last changed.

    • Public ReadOnly Field Accessed: Timestamp field #

      When it was last read.

    • Public ReadOnly Field Created: Timestamp? field #

      When it was made, or Null where the OS or the disk doesn't say.

    • Public ReadOnly Field IsReadOnly: Bool field #

      Whether its owner may not write it.

    • Public Method IsFile(): Bool method #

      Whether it's a file.

    • Public Method IsDirectory(): Bool method #

      Whether it's a folder.

    File class

    Public Class File

    A file's Static Methods, each a call that opens the file, does its work, and closes it.

    std/io/file.fb, line 108

    • @PanicsAtCaller Public Static Method ReadBytes(path: Path, most: Int64 = ARRAY_MOST): UInt8[] Throws IOError static method #

      The file's bytes. One that holds more than most bytes, which an array's most is the default for, throws an IOError of OTHER, found before reading them where the OS knows a file's size, and so does one that memory can't hold. Panics for a most below 0 or above an array's, 2^31 - 1.

    • @PanicsAtCaller Public Static Async Method ReadBytesAsync(path: Path, most: Int64 = ARRAY_MOST): UInt8[] Throws IOError static method #

      What ReadBytes does, without blocking its thread: a call gives its Task.

    • @PanicsAtCaller Public Static Method ReadText(path: Path, most: Int64 = ALL): String Throws IOError static method #

      The file's bytes as text, with U+FFFD for each one that doesn't start well-formed UTF-8. Its line breaks stay as they are, and so does a byte order mark. One that holds more than most bytes, or more than memory does, throws an IOError of OTHER, as ReadBytes does.

    • @PanicsAtCaller Public Static Async Method ReadTextAsync(path: Path, most: Int64 = ALL): String Throws IOError static method #

      What ReadText does, without blocking its thread: a call gives its Task.

    • @PanicsAtCaller Public Static Method ReadLines(path: Path, most: Int64 = ALL): String[] Throws IOError static method #

      The file's text in lines, split at "\n" and at "\r\n", without them. A last line with no line break after it is one too, and an empty file has none. One that holds more than most bytes throws as ReadText does.

    • @PanicsAtCaller Public Static Async Method ReadLinesAsync(path: Path, most: Int64 = ALL): String[] Throws IOError static method #

      What ReadLines does, without blocking its thread: a call gives its Task.

    • Public Static Method WriteBytes(path: Path, bytes: UInt8[]) Throws IOError static method #

      Makes the file hold the bytes, made when it isn't there, and replacing what it held when it is.

    • Public Static Async Method WriteBytesAsync(path: Path, bytes: UInt8[]) Throws IOError static method #

      What WriteBytes does, without blocking its thread: a call gives its Task.

    • Public Static Method WriteText(path: Path, text: String) Throws IOError static method #

      Makes the file hold the text's UTF-8 bytes, as they are, as WriteBytes does.

    • Public Static Async Method WriteTextAsync(path: Path, text: String) Throws IOError static method #

      What WriteText does, without blocking its thread: a call gives its Task.

    • Public Static Method WriteLines(path: Path, lines: String[], ending: LineEnding = LineEnding.LF) Throws IOError static method #

      Makes the file hold the lines, each with ending after it, as WriteBytes does.

    • Public Static Async Method WriteLinesAsync(path: Path, lines: String[], ending: LineEnding = LineEnding.LF) Throws IOError static method #

      What WriteLines does, without blocking its thread: a call gives its Task.

    • Public Static Method AppendBytes(path: Path, bytes: UInt8[]) Throws IOError static method #

      Adds the bytes to the end of the file, made when it isn't there.

    • Public Static Async Method AppendBytesAsync(path: Path, bytes: UInt8[]) Throws IOError static method #

      What AppendBytes does, without blocking its thread: a call gives its Task.

    • Public Static Method AppendText(path: Path, text: String) Throws IOError static method #

      Adds the text's UTF-8 bytes to the end of the file, as AppendBytes does.

    • Public Static Async Method AppendTextAsync(path: Path, text: String) Throws IOError static method #

      What AppendText does, without blocking its thread: a call gives its Task.

    • Public Static Method AppendLines(path: Path, lines: String[], ending: LineEnding = LineEnding.LF) Throws IOError static method #

      Adds the lines, each with ending after it, to the end of the file, as AppendBytes does.

    • Public Static Async Method AppendLinesAsync(path: Path, lines: String[], ending: LineEnding = LineEnding.LF) Throws IOError static method #

      What AppendLines does, without blocking its thread: a call gives its Task.

    • Public Static Method WriteBytesAtomic(path: Path, bytes: UInt8[]) Throws IOError static method #

      Writes the bytes to a new temporary file in the file's folder, onto the disk, then renames it over the file, so the file holds either all of them or what it held before, even if the program or the machine stops partway. On POSIX it keeps the permissions the file had. For a link, the file it leads to is replaced, as a plain write writes through it, and the link stays.

    • Public Static Async Method WriteBytesAtomicAsync(path: Path, bytes: UInt8[]) Throws IOError static method #

      What WriteBytesAtomic does, without blocking its thread: a call gives its Task.

    • Public Static Method WriteTextAtomic(path: Path, text: String) Throws IOError static method #

      Writes the text's UTF-8 bytes atomically, as WriteBytesAtomic does.

    • Public Static Async Method WriteTextAtomicAsync(path: Path, text: String) Throws IOError static method #

      What WriteTextAtomic does, without blocking its thread: a call gives its Task.

    • Public Static Method Exists(path: Path): Bool static method #

      Whether there's a file at the path, or a link to one; not a folder. One the program can't look at isn't there, as far as it can tell.

    • Public Static Async Method ExistsAsync(path: Path): Bool static method #

      What Exists does, without blocking its thread: a call gives its Task.

    • Public Static Method Size(path: Path): Int64 Throws IOError static method #

      How many bytes the file holds. A folder throws an IOError of IS_A_DIRECTORY.

    • Public Static Async Method SizeAsync(path: Path): Int64 Throws IOError static method #

      What Size does, without blocking its thread: a call gives its Task.

    • Public Static Method Metadata(path: Path, followLinks: Bool = True): Metadata Throws IOError static method #

      What's at the path, or at what it links to unless followLinks is False, which gives a link's own.

    • Public Static Async Method MetadataAsync(path: Path, followLinks: Bool = True): Metadata Throws IOError static method #

      What Metadata does, without blocking its thread: a call gives its Task.

    • Public Static Method Copy(from: Path, to: Path) Throws IOError static method #

      Copies the file at from to to, replacing a file there. A folder at either end throws an IOError of IS_A_DIRECTORY.

    • Public Static Async Method CopyAsync(from: Path, to: Path) Throws IOError static method #

      What Copy does, without blocking its thread: a call gives its Task.

    • Public Static Method Move(from: Path, to: Path) Throws IOError static method #

      Moves, or renames, the file or folder at from to to, replacing a file there. A file moved to another disk is copied there, then deleted. A folder goes only where nothing is, else an IOError of ALREADY_EXISTS onto a folder and NOT_A_DIRECTORY onto anything else, and a file onto a folder is IS_A_DIRECTORY, the same on every OS.

    • Public Static Async Method MoveAsync(from: Path, to: Path) Throws IOError static method #

      What Move does, without blocking its thread: a call gives its Task.

    • Public Static Method Delete(path: Path): Bool Throws IOError static method #

      Deletes the file, or the link, at the path, and gives whether there was one. A folder throws an IOError of IS_A_DIRECTORY; Dir.Remove deletes one.

    • Public Static Async Method DeleteAsync(path: Path): Bool Throws IOError static method #

      What Delete does, without blocking its thread: a call gives its Task.

    • Public Static Method Open(path: Path): FileStream Throws IOError static method #

      The file opened to read, as a FileStream from its start.

    • Public Static Async Method OpenAsync(path: Path): FileStream Throws IOError static method #

      What Open does, without blocking its thread: a call gives its Task.

    • @PanicsAtCaller Public Static Method Open(path: Path, options: OpenOptions): FileStream Throws IOError static method #

      The file opened as the options say, as a FileStream from its start, or at its end when it appends. Panics for options no file opens with: none of Read, Write, and Append, or Create, CreateNew, or Truncate without Write or Append, or Truncate with Append.

    • @PanicsAtCaller Public Static Async Method OpenAsync(path: Path, options: OpenOptions): FileStream Throws IOError static method #

      What Open does, without blocking its thread: a call gives its Task.

    • Public Static Method Create(path: Path): FileStream Throws IOError static method #

      A FileStream to write the file, made when it isn't there, and emptied when it is.

    • Public Static Async Method CreateAsync(path: Path): FileStream Throws IOError static method #

      What Create does, without blocking its thread: a call gives its Task.

    • Public Static Method SetReadOnly(path: Path, readOnly: Bool) Throws IOError static method #

      Makes the file read-only, or, when readOnly is False, writable by its owner.

    • Public Static Async Method SetReadOnlyAsync(path: Path, readOnly: Bool) Throws IOError static method #

      What SetReadOnly does, without blocking its thread: a call gives its Task.

    Report an issue with this page or with FutureBlitz on GitHub.