vael:stdio
Bounded synchronous byte readers, writers, and standard output streams.
Available in the vjs (vaeljs) runtime only; absent in vjs-lite.
Provides memory-backed Readable / Writable byte streams bounded by
MAX_BYTES (8 MiB) and synchronous host stdout / stderr writers.
import ... from "vael:stdio"
vaeljs-core (absent in vaeljs-lite-core)Example
Section titled “Example”import { Readable, Writable, stdout } from "vael:stdio";
const reader = new Readable(new Uint8Array([104, 105]));const out = new Uint8Array(2);reader.readSync(out);reader.close();
const writer = new Writable();writer.writeSync("hello\n");writer.end();stdout.writeSync(writer.toUint8Array());writer.close();MAX_BYTESvjs onlyv0.0.0-alpha.0writeSync chunk (8 MiB / 8_388_608 bytes).stdoutvjs onlyv0.0.0-alpha.0stderrvjs onlyv0.0.0-alpha.0Classes
Section titled “Classes”Readable
Section titled “Readable”export class Readable {
constructor(bytes: Uint8Array);
readonly remaining: number;
readonly closed: boolean;
readSync(target: Uint8Array): number;
close(): void;
}
Synchronous reader over an owned snapshot copy of a Uint8Array.
constructor(bytes: Uint8Array);
Copy bytes (attached view, at most MAX_BYTES) into reader-owned storage.
| Name | Type | Description |
|---|---|---|
bytes | Uint8Array | Attached source byte view (at most MAX_BYTES). |
TypeError— whenbytesis not aUint8Arrayor arity is wrong.Error— (name = "StdioError") withcode"VAEL_STDIO_DETACHED"or"VAEL_STDIO_LIMIT".
| Property | Type | Description | Since |
|---|---|---|---|
remaining readonly | number | Remaining unread bytes (0 at EOF and after close()). | v0.0.0-alpha.0 |
closed readonly | boolean | Whether close() has been called. | v0.0.0-alpha.0 |
Readable.readSync
Section titled “Readable.readSync”readSync(target: Uint8Array): number;
Copy up to target.byteLength remaining bytes into target, returning
the number of bytes copied (0 at EOF).
| Name | Type | Description |
|---|---|---|
target | Uint8Array | Attached, non-empty Uint8Array. |
number — Number of bytes copied into target (0 at EOF).TypeError— whentargetis not aUint8Arrayor arity is wrong.Error— (name = "StdioError") withcode"VAEL_STDIO_CLOSED","VAEL_STDIO_DETACHED", or"VAEL_STDIO_ARGUMENT"(emptytarget).
import { Readable } from "vael:stdio";
const r = new Readable(new Uint8Array([1, 2, 3]));const buf = new Uint8Array(2);console.log(r.readSync(buf), r.remaining); // 2 1r.close();Readable.close
Section titled “Readable.close”close(): void;
Release the owned byte snapshot. Idempotent.
voidWritable
Section titled “Writable”export class Writable {
constructor();
readonly kind: "memory" | "stdout" | "stderr";
readonly length: number;
readonly closed: boolean;
readonly ended: boolean;
writeSync(chunk: Uint8Array | string): number;
end(): void;
toUint8Array(): Uint8Array;
close(): void;
}
Synchronous byte writer (either a bounded in-memory buffer or a shared
host stream stdout/stderr).
constructor();
Create an empty memory-backed writer (capacity bounded by MAX_BYTES).
TypeError— when any argument is supplied.
| Property | Type | Description | Since |
|---|---|---|---|
kind readonly | "memory" | "stdout" | "stderr" | Stream backing kind. | v0.0.0-alpha.0 |
length readonly | number | Bytes retained by a memory writer (0 for host streams or after close()). | v0.0.0-alpha.0 |
closed readonly | boolean | Whether close() has been called. | v0.0.0-alpha.0 |
ended readonly | boolean | Whether end() or close() has been called. | v0.0.0-alpha.0 |
Writable.writeSync
Section titled “Writable.writeSync”writeSync(chunk: Uint8Array | string): number;
Synchronously append chunk (or write it to the host stream), returning
the number of bytes accepted.
| Name | Type | Description |
|---|---|---|
chunk | Uint8Array | string | Uint8Array or UTF-8 string (total memory capacity max MAX_BYTES). |
number — Number of bytes written.TypeError— on invalid argument type or arity.Error— (name = "StdioError") withcode"VAEL_STDIO_CLOSED","VAEL_STDIO_ENDED","VAEL_STDIO_DETACHED","VAEL_STDIO_LIMIT", or"VAEL_STDIO_WRITE".
import { Writable } from "vael:stdio";
const w = new Writable();console.log(w.writeSync("hello")); // 5w.close();Writable.end
Section titled “Writable.end”end(): void;
Stop accepting writes while keeping memory-backed content readable. Idempotent.
voidWritable.toUint8Array
Section titled “Writable.toUint8Array”toUint8Array(): Uint8Array;
Return a fresh Uint8Array copy of a memory-backed writer’s contents.
Uint8Array — Fresh Uint8Array copy of accumulated bytes.Error— (name = "StdioError") withcode"VAEL_STDIO_CLOSED"or"VAEL_STDIO_NOT_MEMORY"(when called onstdoutorstderr).
Writable.close
Section titled “Writable.close”close(): void;
Release memory-backed content and retire the writer. Idempotent.
Does not close the underlying OS file descriptor for stdout/stderr.
voidType Aliases
Section titled “Type Aliases”StdioErrorCode
Section titled “StdioErrorCode”export type StdioErrorCode =
| "VAEL_STDIO_DETACHED"
| "VAEL_STDIO_LIMIT"
| "VAEL_STDIO_ARGUMENT"
| "VAEL_STDIO_WRITE"
| "VAEL_STDIO_CLOSED"
| "VAEL_STDIO_ENDED"
| "VAEL_STDIO_NOT_MEMORY";
Error codes reported on StdioError.code (name = "StdioError").
Constants
Section titled “Constants”MAX_BYTES
Section titled “MAX_BYTES”export const MAX_BYTES: 8388608;
Maximum byte capacity of one memory-backed stream or single writeSync
chunk (8 MiB / 8_388_608 bytes).
stdout
Section titled “stdout”export const stdout: Writable;
Shared host writer targeting the current runtime’s standard output.
stderr
Section titled “stderr”export const stderr: Writable;
Shared host writer targeting the current runtime’s standard error.
