std/async/os/file▲toc

Asynchronous file operations.

Currently, this is only supported for the C (with libuv) and NodeJS (jsnode) targets.

type fdstd/async/os/file/fd: V

Read the contents of a file handle to a channel as string fragments (of about the chunk-len (=64 KiB)). Emits a final empty string on end-of-file. Correctly handles partial utf-8 sequences.

Read the contents of a file handle to a channel in chunks of chunk-len (=64 KiB) when possible. Emits a final empty bytesstd/core/types/bytes: V on end-of-file. Note: do not convert byte chunks to a string directly since the may start/end with a partial utf-8 sequence – use fd-read-text-to-channelstd/async/os/file/fd-read-text-to-channel: (fd : fd, ch : channel<string>, chunk-len : ? int) -> <async,exn,ndet> () instead in such case.

type filemodestd/async/os/file/filemode: V

The mode that a (non-seeking) file is opened in.

con Append

Append writes to the end of the file; creates the file if it does not yet exist (“a”).

con Read

Open for reading, fails if the file does not exist (“r”).

Open for reading and writing; truncates an existing file, or creates the file if it does not yet exist (“w+”).

con Write

Open for writing; truncates an existing file, or creates the file if it does not yet exist (“w”).

Automatically generated. Tests for the Append constructor of the filemodestd/async/os/file/filemode: V type.

fun scoped/fd-open( fpath : pathstd/os/path/path: V, fmode : filemodestd/async/os/file/filemode: V, action : (fd : fdstd/async/os/file/fd: V) -> <exnstd/core/exn/exn: (E, V) -> V,fsysstd/core/fsys: X,asyncstd/async/async/async: E|e> a ) : <exnstd/core/exn/exn: (E, V) -> V,fsysstd/core/fsys: X,asyncstd/async/async/async: E|e> a

Open a file descriptor for a given pathstd/os/path/path: (s : string) -> path and file mode fmode and pass it to action. Closes the file descriptor when action returns or finalizes.

fun file-read-text( fpath : pathstd/os/path/path: V ) : <asyncstd/async/async/async: E,exnstd/core/exn/exn: (E, V) -> V,fsysstd/core/fsys: X,ndetstd/core/types/ndet: X> stringstd/core/types/string: V

Read the full contents of a file.

fun file-read-text-to-channel( fpath : pathstd/os/path/path: V, ch : channelstd/async/channel/channel: V -> V<stringstd/core/types/string: V>, chunk-len : ? intstd/core/types/int: V ) : <asyncstd/async/async/async: E,exnstd/core/exn/exn: (E, V) -> V,fsysstd/core/fsys: X,ndetstd/core/types/ndet: X> ()

Emit the full contents of a file to a string channel. Tries to read in chunks of chunk-len (=-1).

fun file-read-to-channel( fpath : pathstd/os/path/path: V, ch : channelstd/async/channel/channel: V -> V<bytesstd/core/types/bytes: V>, chunk-len : ? intstd/core/types/int: V ) : <asyncstd/async/async/async: E,exnstd/core/exn/exn: (E, V) -> V,fsysstd/core/fsys: X,ndetstd/core/types/ndet: X> ()

Emit the full contents of a file to a bytes channel. Tries to read in chunks of chunk-len (=-1).

private import std/core/typesstd/core/types, std/core/hndstd/core/hnd, std/core/exnstd/core/exn, std/core/boolstd/core/bool, std/core/orderstd/core/order, std/core/charstd/core/char, std/core/intstd/core/int, std/core/vectorstd/core/vector, std/core/bytesstd/core/bytes, std/core/bslicestd/core/bslice, std/core/stringstd/core/string, std/core/sslicestd/core/sslice, std/core/liststd/core/list, std/core/maybestd/core/maybe, std/core/maybe2std/core/maybe2, std/core/eitherstd/core/either, std/core/resultstd/core/result, std/core/tuplestd/core/tuple, std/core/lazystd/core/lazy, std/core/showstd/core/show, std/core/debugstd/core/debug, std/core/delayedstd/core/delayed, std/core/consolestd/core/console, std/corestd/core, std/core/undivstd/core/undiv, std/num/int32std/num/int32, std/num/int64std/num/int64, std/os/pathstd/os/path, std/async/asyncstd/async/async, std/async/channelstd/async/channel, std/async/interleavestd/async/interleave, std/async/api/uv/filestd/async/api/uv/file, std/async/internalstd/async/internal