stdionamespacenamespace stdioStandard input, output and error for what a program reads (commons 0001-system FR-019): JSON, a protocol on standard input and output, bytes passed along a pipe. The names are plain (read, readable, write, writeSync, writable). This file and runtime/console.ts are the only files of the runtime that write to standard output or standard error: what a person reads goes through the console (0006-signals FR-026), what a program reads through here.
Writes: write waits until the bytes are handed to the system and gives their length; writeSync writes them all to the file descriptor before it returns (retrying while a non-blocking pipe is full), so it suits the last words of a process that is about to exit. Both write the whole of what they are given. A closed pipe (EPIPE) rejects write and throws from writeSync as the runtime's error; it never ends the process as an uncaught error.
import { stdin, stdout } from "./stdio.ts";
const request = JSON.parse(await stdin.text());
await stdout.write(`${JSON.stringify({ ok: true, request })}\n`);stdionamespacenamespace stdiostdio.Stdintypeno test imports ittype Stdin = {
/** The whole of standard input as a web stream; made once, on first use. Bytes `read` took but did not… (524 characters)type Stdin = {
/** The whole of standard input as a web stream; made once, on first use. Bytes `read` took but did not give come first. */
readonly readable: ReadableStream<Uint8Array>;
/** Reads into `buffer` and gives how many bytes it read, or null at the end of the input. */
read(buffer: Uint8Array): Promise<number | null>;
/** The rest of standard input, to its end, as bytes. */
bytes(): Promise<Uint8Array>;
/** The rest of standard input, to its end, as text (UTF-8). */
text(): Promise<string>;
};Standard input.
stdio.stdinOffunctionno test imports itfunction stdinOf(source: () => ReadableStream<Uint8Array<ArrayBufferLike>>): StdinStandard input over a source stream, made on first use: read keeps what did not fit in its buffer for the next read, and readable gives that first. Exported so a test can drive it with a stream of its own.
stdio.stdinconstno test imports itconst stdin: StdinThis process's standard input.
stdio.Stdouttypeno test imports ittype Stdout = {
/** Writes bytes, or text as UTF-8, and gives how many bytes were written, once they are handed to the… (510 characters)type Stdout = {
/** Writes bytes, or text as UTF-8, and gives how many bytes were written, once they are handed to the system. */
write(data: Uint8Array | string): Promise<number>;
/** Writes bytes, or text as UTF-8, all of them, before it returns; gives how many bytes were written. */
writeSync(data: Uint8Array | string): number;
/** A web stream onto it; closing the stream leaves the file descriptor open, as other writers may still use it. */
readonly writable: WritableStream<Uint8Array>;
};Standard output or standard error, for output a program reads.
stdio.stdoutconstno test imports itconst stdout: StdoutThis process's standard output, for what a program reads.
stdio.stderrconstno test imports itconst stderr: StdoutThis process's standard error, for what a program reads (a person's messages go through runtime/console.ts).
Stdintypeno test imports ittype Stdin = {
/** The whole of standard input as a web stream; made once, on first use. Bytes `read` took but did not… (524 characters)type Stdin = {
/** The whole of standard input as a web stream; made once, on first use. Bytes `read` took but did not give come first. */
readonly readable: ReadableStream<Uint8Array>;
/** Reads into `buffer` and gives how many bytes it read, or null at the end of the input. */
read(buffer: Uint8Array): Promise<number | null>;
/** The rest of standard input, to its end, as bytes. */
bytes(): Promise<Uint8Array>;
/** The rest of standard input, to its end, as text (UTF-8). */
text(): Promise<string>;
};Standard input.
stdinOffunctionfunction stdinOf(source: () => ReadableStream<Uint8Array<ArrayBufferLike>>): StdinStandard input over a source stream, made on first use: read keeps what did not fit in its buffer for the next read, and readable gives that first. Exported so a test can drive it with a stream of its own.
stdinconstno test imports itconst stdin: StdinThis process's standard input.
Stdouttypeno test imports ittype Stdout = {
/** Writes bytes, or text as UTF-8, and gives how many bytes were written, once they are handed to the… (510 characters)type Stdout = {
/** Writes bytes, or text as UTF-8, and gives how many bytes were written, once they are handed to the system. */
write(data: Uint8Array | string): Promise<number>;
/** Writes bytes, or text as UTF-8, all of them, before it returns; gives how many bytes were written. */
writeSync(data: Uint8Array | string): number;
/** A web stream onto it; closing the stream leaves the file descriptor open, as other writers may still use it. */
readonly writable: WritableStream<Uint8Array>;
};Standard output or standard error, for output a program reads.
stdoutconstno test imports itconst stdout: StdoutThis process's standard output, for what a program reads.
stderrconstno test imports itconst stderr: StdoutThis process's standard error, for what a program reads (a person's messages go through runtime/console.ts).