@std/os/fs.ms#
Import each required symbol with import Name from "@std/os/fs.ms".
CloneMode Enum#
Whether a copy asks the filesystem to clone file data (copy-on-write) instead of copying bytes.
enum CloneMode {
Off
Prefer
Require
}CloneMode.Off#
Always copy the bytes; never ask the filesystem to clone.
OffCloneMode.Prefer#
Clone when the filesystem can, otherwise copy bytes.
PreferCloneMode.Require#
Require a native clone; fail when the filesystem cannot.
RequireCopyOptions Type#
Policies for recursive copies, including replacement, symlinks, and optional limits.
type CopyOptions {
recursive Bool = false
replace Bool = false
dereference Bool = false
preserve_timestamps Bool = false
verbatim_symlinks Bool = false
clone CloneMode = CloneMode.Off
max_entries Int? = null
max_bytes Int? = null
filter (fn(String, String) Bool)? = null
}CopyOptions.clone#
Whether to clone file data natively instead of copying bytes.
clone CloneMode = CloneMode.OffCopyOptions.dereference#
When True, symbolic links are followed and their targets copied; when False, links are recreated as links.
dereference Bool = falseCopyOptions.filter#
Called with each source and destination path; the entry is skipped when it returns False. null copies everything.
filter (fn(String, String) Bool)? = nullCopyOptions.max_bytes#
Most file bytes copied in total. Exceeding it returns EOVERFLOW. null sets no limit.
max_bytes Int? = nullCopyOptions.max_entries#
Most files, directories, and links visited, counting the root. Exceeding it returns EOVERFLOW. null sets no limit.
max_entries Int? = nullCopyOptions.preserve_timestamps#
When True, copied files and directories keep the source’s access and modification times.
preserve_timestamps Bool = falseCopyOptions.recursive#
When True, directories are copied with their contents; when False, a directory source returns EINVAL.
recursive Bool = falseCopyOptions.replace#
When True, an existing destination file or link is replaced; when False, an existing destination returns EEXIST.
replace Bool = falseCopyOptions.verbatim_symlinks#
When True, a copied link keeps its target text unchanged. When False, a relative target is rewritten relative to the source directory so it still reaches the original file.
verbatim_symlinks Bool = falseDirectory Type#
An open directory that yields one child per read and must be closed.
opaque type Directory {
}Directory.close#
Releases the directory handle. Safe to call repeatedly; later reads return EBADF.
move fn close() Result[Void, Error]Directory.next#
A directory is a stream source: ReadStream[DirectoryEntry](open_directory(path)?)
yields its children in native order, so steps compose:
... | filter(...) | collect(null). Closing the stream closes the directory.
var fn next() Result[DirectoryEntry?, Error]Directory.path#
Returns the path this cursor was opened with.
fn path() StringDirectoryEntry Type#
The name and kind flags for one child returned by a directory listing.
type DirectoryEntry {
name String
directory Bool
symlink Bool
}DirectoryEntry.directory#
True when the child is a directory; a symbolic link is reported by symlink, not
as a directory.
directory BoolDirectoryEntry.name#
The child’s file name only, without any directory part, in the host’s spelling.
name StringDirectoryEntry.symlink#
True when the child itself is a symbolic link, whatever it points to.
symlink BoolFileEvent Type#
One filesystem change and the affected path.
type FileEvent {
path String
kind String
}FileEvent.kind#
Exactly rename (an entry appeared, disappeared, or was renamed), change
(its contents or metadata changed), or rescan (the queue overflowed and
events were lost; path is the watched root, so look at the tree again).
kind StringFileEvent.path#
Path of the affected entry, formed from the watched path plus any child components.
path StringFileHandle Type#
An open file supporting sequential and positional I/O. It owns its descriptor:
close it, or let its binding go out of scope.
opaque type FileHandle {
}FileHandle.chmod#
Sets the permission bits of the open file to mode (0 through 4095).
fn chmod(mode Int) Result[Void, Error]FileHandle.chown#
Sets the owner and group of the open file by numeric id; -1 leaves that id unchanged. Usually needs privilege.
fn chown(uid Int, gid Int) Result[Void, Error]FileHandle.close#
Closes the file, interrupts calls in progress, and waits for them to stop. Safe to call repeatedly; later operations return EBADF.
move fn close() Result[Void, Error]FileHandle.data_sync#
Flushes the file’s data to stable storage, skipping metadata that is not needed to read it back where the host allows. Hosts without a separate data sync perform a full sync.
fn data_sync() Result[Void, Error]FileHandle.duplicate#
Returns a second handle over a duplicate of the file’s descriptor, which closes on its own. Both share the file position, so a read or write through one moves the other; bytes this handle already read ahead stay with it. A closed handle returns EBADF.
fn duplicate() Result[FileHandle, Error]FileHandle.lock#
Takes an advisory lock like try_lock, retrying every few milliseconds for up to
timeout; null waits until it is granted. Returns False when the timeout passes
first. The wait is a cancellable sleep, so task cancellation ends it.
fn lock(exclusive Bool, timeout Duration? = null) Result[Bool, Error]FileHandle.read#
Returns the next chunk of at most max_bytes (and never more than 64 KiB), or null
at the end of the file. A supplied size must be positive.
fn read(max_bytes Int? = null) Result[Bytes?, Error]FileHandle.read_at#
Reads up to max_bytes at a nonnegative byte offset without moving the position.
A short or empty result means the end of the file was reached.
fn read_at(offset Int, max_bytes Int? = null) Result[Bytes, Error]FileHandle.read_file#
Reads the remaining bytes from the current position; at the end of the file it returns empty Bytes.
fn read_file(max_bytes Int? = null) Result[Bytes, Error]FileHandle.read_lines#
Reads from the current position to the end and returns the lines with their \n
or \r\n terminators removed. Invalid UTF-8 returns EBADMSG, and more bytes than
max_bytes or lines than max_lines returns EOVERFLOW. A negative max_bytes
or max_lines returns EINVAL.
fn read_lines(max_bytes Int? = null, max_lines Int? = null) Result[List[String], Error]FileHandle.read_vectors#
Reads consecutive buffers of the given sizes in bytes and returns the bytes
obtained for each.
offset -1 reads from the current position; other offsets read without moving it. A
buffer is shorter than requested at end of file. A negative size or offset below -1
returns EINVAL.
fn read_vectors(sizes List[Int], offset Int) Result[List[Bytes], Error]FileHandle.reader#
Duplicates this handle for chunk reads; the stream closes its own descriptor independently and shares the file position.
fn reader() Result[ReadStream[Bytes], Error]FileHandle.seek#
Moves the position to offset bytes from origin and returns the new position;
the OS validates the resulting offset.
fn seek(offset Int, origin Seek = Seek.Start) Result[Int, Error]FileHandle.set_times#
Sets the access and modification times of the open file. Returns ENOTSUP on hosts without descriptor timestamps.
fn set_times(accessed Timestamp, modified Timestamp) Result[Void, Error]FileHandle.stat#
Returns metadata for the open file.
fn stat() Result[FileInfo, Error]FileHandle.sync#
Flushes the file’s data and metadata to stable storage.
fn sync() Result[Void, Error]FileHandle.truncate#
Sets the file length to size bytes, discarding the excess or extending with
zero bytes. The current position is not moved. A negative size returns EINVAL.
fn truncate(size Int) Result[Void, Error]FileHandle.try_lock#
Tries to take an advisory lock on the whole file without waiting: shared (many readers) or exclusive (one writer).
Returns False when another handle holds a conflicting lock. The lock is advisory: it only excludes other lockers (flock on Unix, LockFileEx on Windows), and closing the handle releases it.
Handles made by clone share one lock, and locking a handle that already holds one converts it. A closed handle returns EBADF.
fn try_lock(exclusive Bool) Result[Bool, Error]FileHandle.unlock#
Releases the advisory lock this handle holds; releasing when null is held succeeds.
fn unlock() Result[Void, Error]FileHandle.write#
Writes all of data (text as UTF-8) at the current position; errors can leave a
prefix. Does not truncate or reposition this handle. Writes at the end only when
the handle was opened in an append mode.
fn write(data Writable) Result[Void, Error]FileHandle.write_at#
Writes all of data (text as UTF-8) at a nonnegative offset without moving the
position; a handle opened for append returns EINVAL because the host would ignore
the offset; errors can leave a prefix.
fn write_at(offset Int, data Writable) Result[Void, Error]FileHandle.write_vectors#
Writes every buffer; offset -1 uses the current position. A nonnegative offset on a handle opened for append returns EINVAL.
fn write_vectors(buffers List[Bytes], offset Int) Result[Void, Error]FileHandle.writer#
Duplicates this handle for chunk writes, as reader does for reads; flushing the
stream syncs the file.
fn writer() Result[WriteStream[Bytes], Error]FileInfo Type#
File metadata, including portable fields and exact platform-specific numeric values.
type FileInfo {
name String
size Int
kind FileKind
modified Timestamp
accessed Timestamp
changed Timestamp
mode Int
permissions Int
block_size Int
blocks Int
rdev Int
exact Map[String, BigInt]
device Int
inode Int
links Int
uid Int
gid Int
created Timestamp? = null
}FileInfo.accessed#
Time the file was last read; it falls back to modified where the host lacks
access times.
accessed TimestampFileInfo.block_size#
Preferred I/O block size in bytes; unavailable fields are zero.
block_size IntFileInfo.blocks#
Allocated 512-byte blocks on POSIX hosts; unavailable fields are zero.
blocks IntFileInfo.changed#
Time the file’s metadata or contents last changed; it falls back to modified
where the host lacks it.
changed TimestampFileInfo.created#
Birth time of the file, or null when the host or filesystem does not record it.
created Timestamp? = nullFileInfo.device#
Id of the device that holds the file; with inode it identifies the file. 0
where unavailable.
device IntFileInfo.exact#
Unbounded copies of the numeric fields size, mode, device, inode,
links,
uid, gid, block_size, blocks, and rdev, which cannot overflow.
It also holds the times as nanoseconds since the Unix epoch under accessed_ns,
modified_ns, changed_ns, and created_ns. Unavailable values are 0.
exact Map[String, BigInt]FileInfo.gid#
Numeric id of the owning group; 0 where unavailable.
gid IntFileInfo.inode#
The file’s index number on its device; 0 where unavailable.
inode IntFileInfo.kind#
What the entry is. A symbolic link is Symlink only when links were not
followed.
kind FileKindFileInfo.links#
Number of hard links to the file; 0 where unavailable.
links IntFileInfo.mode#
POSIX mode bits: the file-type bits such as 0100000 for a regular file, plus permission and setuid, setgid, and sticky bits.
mode IntFileInfo.modified#
Time the file’s contents were last changed.
modified TimestampFileInfo.name#
The final path component’s file name only.
name StringFileInfo.permissions#
Only the permission, setuid, setgid, and sticky bits of mode, 0 through 4095.
permissions IntFileInfo.rdev#
Device id the entry represents when it is a device file, otherwise 0.
rdev IntFileInfo.size#
File length in bytes.
size IntFileInfo.uid#
Numeric id of the owning user; 0 where unavailable.
uid IntFileInfo.is_directory#
True for a directory.
fn is_directory() BoolFileInfo.is_file#
True for an ordinary file.
fn is_file() BoolFileInfo.is_symlink#
True for a symbolic link itself, which only happens when links were not followed.
fn is_symlink() BoolFileKind Enum#
What kind of filesystem object an entry is.
enum FileKind {
File
Directory
Symlink
Fifo
Socket
BlockDevice
CharDevice
}FileKind.BlockDevice#
A block special device.
BlockDeviceFileKind.CharDevice#
A character special device.
CharDeviceFileKind.Directory#
A directory that lists child entries.
DirectoryFileKind.Fifo#
A named pipe (FIFO) used for inter-process byte streams.
FifoFileKind.File#
An ordinary file holding bytes.
FileFileKind.Socket#
A Unix domain socket file.
SocketFileKind.Symlink#
A symbolic link itself (only reported when links are not followed).
SymlinkFileSystemInfo Type#
Capacity and free-space statistics for a filesystem. block_size is in bytes; the
block fields count blocks of that size; files and files_free count native file
nodes (zero if unavailable).
type FileSystemInfo {
type_id Int
block_size Int
blocks Int
blocks_free Int
blocks_available Int
files Int
files_free Int
}FileSystemInfo.block_size#
Size in bytes of the blocks that blocks, blocks_free, and blocks_available
count.
block_size IntFileSystemInfo.blocks#
Total number of blocks in the filesystem.
blocks IntFileSystemInfo.blocks_available#
Number of unused blocks available to unprivileged users.
blocks_available IntFileSystemInfo.blocks_free#
Number of unused blocks, including space reserved for privileged users.
blocks_free IntFileSystemInfo.files#
Total number of file nodes, such as inodes, the filesystem can hold; 0 where unavailable.
files IntFileSystemInfo.files_free#
Number of unused file nodes; 0 where unavailable.
files_free IntFileSystemInfo.type_id#
The host’s numeric filesystem type code, such as the magic number reported by Linux; 0 where unavailable.
type_id IntGlobOptions Type#
Include and exclude patterns and limits used by filesystem glob operations.
type GlobOptions {
patterns List[String]
exclude List[String] = []
follow_links Bool = false
max_entries Int? = null
max_results Int? = null
}GlobOptions.exclude#
Glob patterns for entries to skip; a match is neither returned nor searched further.
exclude List[String] = []GlobOptions.follow_links#
When True, symbolic links to directories are traversed, with cycles detected; when False, links are reported but not entered.
follow_links Bool = falseGlobOptions.max_entries#
Most filesystem entries visited while searching. Exceeding it returns EOVERFLOW. null sets no limit.
max_entries Int? = nullGlobOptions.max_results#
Most distinct matches returned. Exceeding it returns EOVERFLOW. null sets no limit.
max_results Int? = nullGlobOptions.patterns#
Glob patterns to include; an entry that matches any of them is returned.
patterns List[String]OpenMode Enum#
How open treats the file.
enum OpenMode {
Read
ReadWrite
Write
WriteRead
Append
AppendRead
}OpenMode.Append#
Write at the end, creating the file when absent.
AppendOpenMode.AppendRead#
Read and write at the end, creating the file when absent.
AppendReadOpenMode.Read#
Read an existing file.
ReadOpenMode.ReadWrite#
Read and write an existing file.
ReadWriteOpenMode.Write#
Write, creating the file or truncating it.
WriteOpenMode.WriteRead#
Read and write, creating the file or truncating it.
WriteReadOpenOptions Type#
Settings of open beyond the mode.
type OpenOptions {
exclusive Bool = false
permissions Int = 438
}OpenOptions.exclusive#
When True, creating a file that already exists returns EEXIST. Applies to
Write, WriteRead, Append and AppendRead.
exclusive Bool = falseOpenOptions.permissions#
Permission bits, from 0 through 4095, given to a created file, subject to umask and OS policy. The default is 438 (0666).
permissions Int = 438PathEntry Type#
A matched path together with its filesystem entry metadata.
type PathEntry {
path String
entry DirectoryEntry
}PathEntry.entry#
The directory entry record for the match: name, directory flag, and symlink flag.
entry DirectoryEntryPathEntry.path#
The matched path relative to the glob root, always /-separated.
path StringRawWatcher Type#
The native watcher a watch operation returns; watch wraps it into a stream.
opaque type RawWatcher {
}Seek Enum#
The position a seek offset counts from.
enum Seek {
Start
Current
End
}Seek.Current#
The handle’s current position; the offset is relative to it and may be negative.
CurrentSeek.End#
The end of the file.
EndSeek.Start#
The start of the file.
StartTemporaryDirectory Type#
A temporary directory whose contents are removed when it is closed.
opaque type TemporaryDirectory {
}TemporaryDirectory.close#
Removes the directory and everything inside it. Safe to call repeatedly.
move fn close() Result[Void, Error]TemporaryDirectory.path#
Returns the absolute path of the directory, created under the host’s temporary root.
fn path() StringWatchOptions Type#
How watch observes a path: with native OS events by default, or by polling snapshots when interval is set.
Every field has a default, so WatchOptions() watches natively with no limits and WatchOptions(interval: seconds(1)) polls.
max_events and overflow apply only to native watching; combining them with interval returns EINVAL.
type WatchOptions {
interval Duration? = null
max_entries Int? = null
max_events Int? = null
overflow String? = null
}WatchOptions.interval#
Polling period, which must be positive. null watches with native OS events.
interval Duration? = nullWatchOptions.max_entries#
Most paths under the root, counted when the watcher starts. Exceeding it returns EOVERFLOW. null sets no limit.
max_entries Int? = nullWatchOptions.max_events#
Most queued native events. Native watchers only. null sets no limit.
max_events Int? = nullWatchOptions.overflow#
What a native watcher does when its queue overflows: exactly rescan (default),
which drops the queued events and queues one rescan event for the watched root,
error (the stream fails with EOVERFLOW), or ignore. Native watchers only.
overflow String? = nullaccess Function#
Checks that the process may access path in mode, from 0 through 7: 0 checks
existence, 4 read, 2 write, 1 execute, and a sum of them checks several at once.
Native permissions and Windows access policy still apply. A missing path returns
ENOENT.
fn access(path String, mode Int) Result[Void, Error] { ... }append_file Function#
Starts appending data (text or Bytes) to the end of the file and returns its
promise, creating the file with mode 0600 when absent. Writes every byte or fails,
possibly leaving a partial append.
fn append_file(path String, data Writable) Promise[Void] { ... }canonicalize Function#
Resolves symlinks and returns the canonical absolute path.
fn canonicalize(path String) Result[String, Error] { ... }chmod Function#
Sets the permission bits of path to mode, from 0 through 4095. follow_links
True (the default) follows a final symbolic link; False changes the link itself,
which returns ENOTSUP on hosts lacking this operation.
fn chmod(path String, mode Int, follow_links Bool = true) Result[Void, Error] { ... }chown Function#
Sets the owning user and group of path by numeric id; -1 leaves that id unchanged.
follow_links True (the default) follows a final symbolic link; False changes the link
itself, with ENOTSUP on hosts lacking this operation.
Usually needs privilege, and Windows returns ENOTSUP.
fn chown(path String, uid Int, gid Int, follow_links Bool = true) Result[Void, Error] { ... }copy Function#
Copies a file or, with options.recursive, a directory tree.
By default an existing destination returns EEXIST; set replace to overwrite it. options.filter is called with each
source and destination path and skips the entry when it returns False.
Entry and byte limits apply cumulatively across the whole copy.
import CopyOptions, copy from "@std/os/fs.ms"
copy("a.txt", "b.txt", CopyOptions(replace: true))?fn copy(source String, destination String, options CopyOptions = CopyOptions()) Result[Void, Error] { ... }create_directory Function#
Creates one directory; recursive defaults to False, requiring its parent to exist.
fn create_directory(path String, recursive Bool = false) Result[Void, Error] { ... }create_hard_link Function#
Creates destination as another name for the file at source. An existing
destination returns EEXIST; it must be on the same filesystem as source.
fn create_hard_link(source String, destination String) Result[Void, Error] { ... }create_symlink Function#
Creates a symbolic link at path pointing to target.
fn create_symlink(path String, target String) Result[Void, Error] { ... }exists Function#
Reports whether path names anything. A missing path (ENOENT) or a missing directory
part (ENOTDIR, such as file.txt/child) is false; any other failure, such as a
permission error, is returned so it is not mistaken for absence. A dangling link is
false unless follow_links is False.
fn exists(path String, follow_links Bool = true) Result[Bool, Error] { ... }glob Function#
Returns entries matching the include patterns of options, sorted by path. path is the root; each result’s
path is relative to it and always /-separated. exclude skips an entry (and does not enter a skipped directory) when it
returns True. A pattern ending in / matches directories only, as in a shell. A malformed pattern, one over 4096 bytes, or a negative limit returns EINVAL.
import GlobOptions, glob from "@std/os/fs.ms"
sources := glob(".", GlobOptions(patterns: ["*.ms"]))?
print(sources.length())fn glob(path String, options GlobOptions, move exclude (fn(PathEntry) Bool)? = null) Result[List[PathEntry], Error] { ... }list Function#
Lists a directory in native order. A directory with more than max_entries entries
returns EOVERFLOW rather than a shortened list, and a negative max_entries returns
EINVAL; null sets no limit. A name that is not valid UTF-8 is listed with U+FFFD in
place of each invalid byte, so it no longer addresses the entry. The same holds for
glob, stat names and directory cursors.
fn list(path String, max_entries Int? = null) Result[List[DirectoryEntry], Error] { ... }move Function#
Moves a file or tree from source to destination, across filesystems too. It
renames when it can. When the rename fails with EIO, as a move across devices does,
it copies the tree, then removes source, and removes the partial copy if copying
fails. The copy fallback does not replace an existing destination and returns EEXIST.
fn move(source String, destination String) Result[Void, Error] { ... }open Function#
Opens path in mode (default Read). options.exclusive makes creation fail with EEXIST when the file exists;
options.permissions is applied on creation, subject to umask and OS policy.
import OpenMode, open from "@std/os/fs.ms"
var file = open("out.log", OpenMode.Append)?
file.close()?fn open(path String, mode OpenMode = OpenMode.Read, options OpenOptions = OpenOptions()) Result[FileHandle, Error] { ... }open_directory Function#
Opens path as a directory cursor that yields one child per read in native order;
close it when done. It is also a stream source:
stream[DirectoryEntry](open_directory(path)?). A path that is not a directory
returns EINVAL.
fn open_directory(path String) Result[Directory, Error] { ... }read_file Function#
Starts reading a file fully into memory and returns its promise. Supply max_bytes
for untrusted or large files.
fn read_file(path String, max_bytes Int? = null) Promise[Bytes] { ... }read_symlink Function#
Returns the target text stored in the symbolic link at path, without resolving it.
A path that is not a link returns EINVAL.
fn read_symlink(path String) Result[String, Error] { ... }remove Function#
Removes a file or an empty directory. With recursive, it removes a directory and
everything inside it; otherwise a nonempty directory returns ENOTEMPTY. A missing
path returns ENOENT, except that a recursive removal of a missing path succeeds.
fn remove(path String, recursive Bool = false) Result[Void, Error] { ... }rename Function#
Moves source to destination using the operating system’s rename, applying its
rules for replacing an existing destination. It never falls back to copying, so a
move across devices returns an error.
fn rename(source String, destination String) Result[Void, Error] { ... }set_times Function#
Sets the access and modification times of path. follow_links True (the default)
follows a final symbolic link; False updates the link itself, with ENOTSUP where the
host lacks it, such as Windows.
fn set_times(path String, accessed Timestamp, modified Timestamp, follow_links Bool = true) Result[Void, Error] { ... }stat Function#
Returns metadata for path. follow_links True (the default) describes the link
target and False describes the link itself.
fn stat(path String, follow_links Bool = true) Result[FileInfo, Error] { ... }stat_filesystem Function#
Returns capacity and free-space statistics for the filesystem containing path.
Hosts without the query return ENOTSUP.
fn stat_filesystem(path String) Result[FileSystemInfo, Error] { ... }temporary Function#
Creates a new temporary directory that is removed, with its contents, when it is
closed, as at the end of its scope. prefix follows the rules of
temporary_directory.
fn temporary(prefix String) Result[TemporaryDirectory, Error] { ... }temporary_directory Function#
Creates a new directory under the host’s temporary directory and returns its path;
the caller must remove it. prefix must be nonempty and contain no slash, backslash,
or NUL. The name is the prefix followed by random digits. If the prefix has a *,
the last one marks where the digits go instead, so "build-*.tmp" makes
build-4123.tmp.
fn temporary_directory(prefix String) Result[String, Error] { ... }temporary_root Function#
Returns the host’s temporary directory path, without creating or checking it.
fn temporary_root() Result[String, Error] { ... }truncate Function#
Sets the length of the file at path to size bytes, following a final symbolic
link.
fn truncate(path String, size Int) Result[Void, Error] { ... }watch Function#
Watches path for changes and returns the changes as a stream, one event per item. Dropping the stream stops the watcher.
When path itself is removed or moved away, the stream delivers that event and then ends (next returns null).
With recursive, a directory that appears is watched at once and its existing entries are reported as rename events.
Without options.interval it uses native OS events (inotify on Linux, kqueue on macOS, ReadDirectoryChangesW on Windows).
With an interval it compares snapshots of the tree every interval, which must be positive, and can miss transient changes;
max_events and overflow apply only to native events and return EINVAL together with an interval.
max_entries bounds the paths under the root (the root, files and directories), counted when the watcher starts, and
fails with EOVERFLOW the same way on every platform.
import WatchOptions, watch from "@std/os/fs.ms"
var watcher = watch("src", recursive: true, options: WatchOptions(interval: 1.seconds()))?
watcher.close()?fn watch(path String, recursive Bool = false, options WatchOptions = WatchOptions()) Result[ReadStream[FileEvent], Error] { ... }write_atomic Function#
Starts replacing the file at path with data (text or Bytes) all-or-nothing and returns its promise: readers see the old contents or the new, never a partial file.
The data goes to a new file beside path, is synced to stable storage, and then renamed over path, so the directory of path must be writable.
When path is a symbolic link, the file it names is replaced and the link stays; a link that cannot be resolved is replaced itself.
An existing file keeps its permission bits and a new one gets 0644. On failure the temporary file is removed and path is unchanged.
Example: write_atomic("config.json", text).wait().
fn write_atomic(path String, data Writable) Promise[Void] { ... }write_file Function#
Starts writing data to a new file at path and returns its promise. data is text
(written as UTF-8) or Bytes. By default an existing file returns EEXIST; set
replace to overwrite it.
fn write_file(path String, data Writable, replace Bool = false) Promise[Void] { ... }