IF Commons GitHub

stdio

Written to: 1 requirement: 1 proved, 0 partly, 0 failing, 0 with no test recorded. 0001-system FR-019

Standard 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`);

Source: commons/system/src/stdio.ts

1 of 12 exports are imported by a test of the run. A test that imports an export may not call it or check what it returns.

stdionamespace
namespace stdio
stdio.Stdintypeno test imports it
type 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 it
function stdinOf(source: () => ReadableStream<Uint8Array<ArrayBufferLike>>): Stdin

Standard 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 it
const stdin: Stdin

This process's standard input.

stdio.Stdouttypeno test imports it
type 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 it
const stdout: Stdout

This process's standard output, for what a program reads.

stdio.stderrconstno test imports it
const stderr: Stdout

This process's standard error, for what a program reads (a person's messages go through runtime/console.ts).

Stdintypeno test imports it
type 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.

stdinOffunction
function stdinOf(source: () => ReadableStream<Uint8Array<ArrayBufferLike>>): Stdin

Standard 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.

Imported by 4 tests of the run (4 passed, 0 failed): the library's results

stdinconstno test imports it
const stdin: Stdin

This process's standard input.

Stdouttypeno test imports it
type 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 it
const stdout: Stdout

This process's standard output, for what a program reads.

stderrconstno test imports it
const stderr: Stdout

This process's standard error, for what a program reads (a person's messages go through runtime/console.ts).

Titles, headings, exports, tables, columns and requirements. Esc closes.