A reference to stdin
which can be used to read directly from stdin
.
It implements the Deno 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 Deno.stdin.readable) { const text = decoder.decode(chunk); // do something with the text }
readable: ReadableStream<Uint8Array>
A readable stream interface to stdin
.
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 Deno.stdin.read(buf); // 11 bytes const text = new TextDecoder().decode(buf); // "hello world"
readSync(p: Uint8Array): number | null
Synchronously 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 = Deno.stdin.readSync(buf); // 11 bytes const text = new TextDecoder().decode(buf); // "hello world"
close(): void
Closes stdin
, freeing the resource.
Deno.stdin.close();
setRaw(mode: boolean,options?: SetRawOptions,): void
Set 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.
Deno.stdin.setRaw(true, { cbreak: true });
isTerminal(): boolean
Checks if stdin
is a TTY (terminal).
// This example is system and context specific Deno.stdin.isTerminal(); // true