velt/io
API referenceThe error type the I/O modules share: files (velt/fs), sockets (velt/net), child processes and WebSockets all throw IoError. The module also holds the streams (ReadableStream and its reader and controller), which are globals and need no import. For a walkthrough, read the guide.
Exports
Error is the prelude base class).ReadableStreamDefaultControllerThe handle a source gets to its stream: enqueue(chunk), close(), error(e) and desiredSize (how many more chunks the queue wants).ReadableStreamDefaultReaderReads a stream it holds (JS ReadableStreamDefaultReader): read() the next chunk, releaseLock() to let go, cancel(reason), and closed.ReadableStreamA stream of chunks (JS ReadableStream): made from a source (new ReadableStream({ start, pull, cancel })) or an async iterable (ReadableStream.from), and read with a reader (getReader()), with for await, or as a Response body.QueuingStrategyHow many chunks a stream queues before it stops pulling (JS's count queuing strategy).UnderlyingSourceWhat a ReadableStream reads from (JS's underlying source).CancelReasonWhy a stream was cancelled, as given to cancel(reason) (JS takes any value).ReadableStreamReadResultOne step of reader.read(): { value, done: false }, or { done: true } once closed.Re-exported from velt/io/error
class IoError extends ErrorA failed I/O operation (Error is the prelude base class). code is the Node-style name:
"ENOENT", "EACCES", "EEXIST", "EINVAL", "EILSEQ", "ETIMEDOUT", "ECONNREFUSED", "ECONNRESET",
"EADDRINUSE", "EPIPE", "EOF", "ENOTSUP", "ENOTDIR", "ENOTEMPTY", "EISDIR", "EBADF" (a closed
socket, file stream, child process or WebSocket handle) or "UNKNOWN".
Returned byvelt/fsFileReader.linesvelt/nativeioErrorvelt/net/httpBodyStream.[Symbol.asyncIterator]fetchRequest.textResponse.textRequestSource.readvelt/net/websocketWebSocket.[Symbol.asyncIterator]and 1 moreThrown byvelt/net/httpresponsePartsRequest.constructorResponse.cloneUsed byReadableStream.[BYTE_CHUNKS]velt/net/websocketWebSocket
code: stringNo doc comment yetconstructor(code: string, message: string)No doc comment yetRe-exported from velt/io/streams/controller
class ReadableStreamDefaultController<R>The handle a source gets to its stream: enqueue(chunk), close(), error(e) and
desiredSize (how many more chunks the queue wants). Streams make it; JS has no public
constructor either.
Used byUnderlyingSource.start
get desiredSize(): number | nullHow many more chunks the queue wants: the high-water mark minus the chunks queued, 0 once closed, null once errored.
enqueue(chunk: R)Adds chunk to the stream: the oldest waiting read gets it, or it is queued.
close()Closes the stream: reads get the queued chunks, then done.
error(e: unknown)Errors the stream with e: queued chunks are dropped and reads reject with e.
[ [INSPECT](): stringHow console.log shows the controller, as Node does.
Re-exported from velt/io/streams/reader
class ReadableStreamDefaultReader<R>Reads a stream it holds (JS ReadableStreamDefaultReader): read() the next chunk,
releaseLock() to let go, cancel(reason), and closed.
Returned byReadableStream.getReader
constructor(stream: ReadableStream<R>)A reader holding stream; a TypeError when another reader holds it.
read(): Promise<ReadableStreamReadResult<R>, unknown>The next chunk ({ value, done: false }), or { done: true } once the stream is closed.
releaseLock()Lets go of the stream: another reader may take it, and waiting reads reject.
cancel(reason: CancelReason = null): Promise<void, unknown>Cancels the stream (see ReadableStream.cancel).
get closed(): Promise<void, unknown>Settles when the stream closes (or rejects when it errors); rejects with TypeError:
Invalid state: Reader released once the reader let go of the stream.
[ [INSPECT](): stringHow console.log shows the reader, as Node does.
Re-exported from velt/io/streams/streams
class ReadableStream<R> extends ByteSourceA stream of chunks (JS ReadableStream): made from a source (new ReadableStream({ start,
pull, cancel })) or an async iterable (ReadableStream.from), and read with a reader
(getReader()), with for await, or as a Response body.
Parameter ofReadableStreamDefaultReader.constructor
constructor(source: UnderlyingSource<R> = {}, strategy: QueuingStrategy = {}) throws unknownA stream reading from source; strategy.highWaterMark is how many chunks it queues ahead
of the reads (default 1).
static from<T, E>(src: AsyncIterable<T, E>): ReadableStream<T>A stream of the values src yields (an async generator, any async iterable).
get locked(): boolWhether a reader holds the stream (getReader() until releaseLock()).
cancel(reason: CancelReason = null): Promise<void, unknown>Cancels the stream: queued chunks are dropped, the source's cancel(reason) runs, and
reads get done. Rejects with a TypeError while a reader holds the stream (cancel
through the reader then).
getReader(): ReadableStreamDefaultReader<R>A reader that holds the stream; a TypeError when another one does.
[Symbol.asyncIterator](): AsyncIterator<R, Reason>for await (const chunk of stream): reads to the end; leaving the loop early cancels the stream.
[ [BYTE_CHUNKS](): AsyncIterator<u8[], IoError | AbortError>The chunks as a body's bytes (std only: new Response(stream), a request body): each one
must be a Uint8Array (copied, as a body's bytes are), else the read fails as Node's does.
[ [INSPECT](): stringHow console.log shows the stream, as Node does.
Re-exported from velt/io/streams/types
How many chunks a stream queues before it stops pulling (JS's count queuing strategy).
Parameter ofReadableStream.constructor
highWaterMark?: numberThe queue length the stream pulls up to (default 1; 0 pulls only for a waiting read).
Re-exported from velt/io/streams/types
interface UnderlyingSource<R>What a ReadableStream reads from (JS's underlying source). start(controller) runs when the
stream is made, pull(controller) whenever the stream wants more chunks (it enqueues them, or
closes the stream), and cancel(reason) when a consumer cancels it. Each may be async, and
an error it throws errors the stream.
Parameter ofReadableStream.constructor
start?: ((controller: ReadableStreamDefaultController<R>) => void throws unknown) | ((controller: ReadableStreamDefaultController<R>) => Promise<void, unknown>)No doc comment yetpull?: ((controller: ReadableStreamDefaultController<R>) => void throws unknown) | ((controller: ReadableStreamDefaultController<R>) => Promise<void, unknown>)No doc comment yetcancel?: ((reason: CancelReason) => void throws unknown) | ((reason: CancelReason) => Promise<void, unknown>)No doc comment yetRe-exported from velt/io/streams/types
type CancelReason = Error | string | nullWhy a stream was cancelled, as given to cancel(reason) (JS takes any value).
Parameter ofReadableStreamDefaultReader.cancelReadableStream.cancelUsed byUnderlyingSource.cancel
Re-exported from velt/io/streams/types
type ReadableStreamReadResult<R> = IteratorResult<R>One step of reader.read(): { value, done: false }, or { done: true } once closed.
Returned byReadableStreamDefaultReader.read