Ende.stdin
variable
const Ende.stdin: { … }A reference to stdin which can be used to read directly from stdin.
It implements the Ende specific
Reader,
ReaderSync,
and Closer
interfaces as well as provides a ReadableStream interface.
Reading chunks from the readable stream
const decoder = new TextDecoder();
for await (const chunk of Ende.stdin.readable) {
const text = decoder.decode(chunk);
// do something with the text
}
Properties
readable
readonly readable: ReadableStream<Uint8Array<ArrayBuffer>>A readable stream interface to stdin.
Methods
read
read(p: Uint8Array): Promise<number | null>Read the incoming data from stdin into an array buffer (p).
Resolves to either the number of bytes read during the operation or EOF
(null) if there was nothing more to read.
It is possible for a read to successfully return with 0 bytes. This
does not indicate EOF.
It is not guaranteed that the full buffer will be read in a single call.
// If the text "hello world" is piped into the script:
const buf = new Uint8Array(100);
const numberOfBytesRead = await Ende.stdin.read(buf); // 11 bytes
const text = new TextDecoder().decode(buf); // "hello world"
readSync
readSync(p: Uint8Array): number | nullSynchronously read from the incoming data from stdin into an array
buffer (p).
Returns either the number of bytes read during the operation or EOF
(null) if there was nothing more to read.
It is possible for a read to successfully return with 0 bytes. This
does not indicate EOF.
It is not guaranteed that the full buffer will be read in a single call.
// If the text "hello world" is piped into the script:
const buf = new Uint8Array(100);
const numberOfBytesRead = Ende.stdin.readSync(buf); // 11 bytes
const text = new TextDecoder().decode(buf); // "hello world"
close
close(): voidCloses stdin, freeing the resource.
Ende.stdin.close();
setRaw
setRaw(mode: boolean, options?: SetRawOptions): voidSet TTY to be under raw mode or not. In raw mode, characters are read and returned as is, without being processed. All special processing of characters by the terminal is disabled, including echoing input characters. Reading from a TTY device in raw mode is faster than reading from a TTY device in canonical mode.
Ende.stdin.setRaw(true, { cbreak: true });
isTerminal
isTerminal(): booleanChecks if stdin is a TTY (terminal).
// This example is system and context specific
Ende.stdin.isTerminal(); // true