I/O
Interfaces for reading, writing, seeking, and managing resources. For handling of data streams, file I/O, and console interactions.
Enums
Functions
Interfaces
Option which can be specified when performing Deno.inspect.
Variables
A reference to stderr which can be used to write directly to stderr.
It implements the Deno specific
Writer,
WriterSync,
and Closer interfaces as well as provides a
WritableStream interface.
A reference to stdin which can be used to read directly from stdin.
A reference to stdout which can be used to write directly to stdout.
It implements the Deno specific
Writer,
WriterSync,
and Closer interfaces as well as provides a
WritableStream interface.
enum Deno.SeekMode
function Deno.consoleSize
#consoleSize(): { columns: number; rows: number; }Gets the size of the console as columns/rows.
const { columns, rows } = Deno.consoleSize();
This returns the size of the console window as reported by the operating system. It's not a reflection of how many characters will fit within the console window, but can be used as part of that calculation.
Throws if none of stdin, stdout, or stderr is connected to a terminal
(e.g. all are piped or redirected). Use Deno.stdout.isTerminal
to check before calling.
Return Type #
{ columns: number; rows: number; } function Deno.inspect
#inspect(value: unknown,options?: InspectOptions,): stringConverts the input into a string that has the same format as printed by
console.log().
const obj = {
a: 10,
b: "hello",
};
const objAsString = Deno.inspect(obj); // { a: 10, b: "hello" }
console.log(obj); // prints same value as objAsString, e.g. { a: 10, b: "hello" }
A custom inspect functions can be registered on objects, via the symbol
Symbol.for("Deno.customInspect"), to control and customize the output
of inspect() or when using console logging:
class A {
x = 10;
y = "hello";
[Symbol.for("Deno.customInspect")]() {
return `x=${this.x}, y=${this.y}`;
}
}
const inStringFormat = Deno.inspect(new A()); // "x=10, y=hello"
console.log(inStringFormat); // prints "x=10, y=hello"
A depth can be specified by using the depth option:
Deno.inspect({a: {b: {c: {d: 'hello'}}}}, {depth: 2}); // { a: { b: [Object] } }
Parameters #
#value: unknown #options: InspectOptions Return Type #
string interface Deno.InspectOptions
Option which can be specified when performing Deno.inspect.
Properties #
#breakLength: number = 80 The maximum length for an inspection to take up a single line.
#escapeSequences: boolean = true Whether or not to escape sequences.
#iterableLimit: number = 100 The maximum number of iterable entries to print.
#trailingComma: boolean = false Add a trailing comma for multiline collections.
#strAbbreviateSize: number The maximum length of a string before it is truncated with an ellipsis.
interface Deno.SetRawOptions
variable Deno.stderr
A reference to stderr which can be used to write directly to stderr.
It implements the Deno specific
Writer,
WriterSync,
and Closer interfaces as well as provides a
WritableStream interface.
These are low level constructs, and the console interface is a
more straight forward way to interact with stdout and stderr.
Properties #
Methods #
Write the contents of the array buffer (p) to stderr.
Resolves to the number of bytes written.
It is not guaranteed that the full buffer will be written in a single call.
const encoder = new TextEncoder();
const data = encoder.encode("Hello world");
const bytesWritten = await Deno.stderr.write(data); // 11
Synchronously write the contents of the array buffer (p) to stderr.
Returns the number of bytes written.
It is not guaranteed that the full buffer will be written in a single call.
const encoder = new TextEncoder();
const data = encoder.encode("Hello world");
const bytesWritten = Deno.stderr.writeSync(data); // 11
#isTerminal(): boolean Checks if stderr is a TTY (terminal).
// This example is system and context specific
Deno.stderr.isTerminal(); // true
variable Deno.stdin
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
}
Properties #
Methods #
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"
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"
#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
variable Deno.stdout
A reference to stdout which can be used to write directly to stdout.
It implements the Deno specific
Writer,
WriterSync,
and Closer interfaces as well as provides a
WritableStream interface.
These are low level constructs, and the console interface is a
more straight forward way to interact with stdout and stderr.
Properties #
Methods #
Write the contents of the array buffer (p) to stdout.
Resolves to the number of bytes written.
It is not guaranteed that the full buffer will be written in a single call.
const encoder = new TextEncoder();
const data = encoder.encode("Hello world");
const bytesWritten = await Deno.stdout.write(data); // 11
Synchronously write the contents of the array buffer (p) to stdout.
Returns the number of bytes written.
It is not guaranteed that the full buffer will be written in a single call.
const encoder = new TextEncoder();
const data = encoder.encode("Hello world");
const bytesWritten = Deno.stdout.writeSync(data); // 11
#isTerminal(): boolean Checks if stdout is a TTY (terminal).
// This example is system and context specific
Deno.stdout.isTerminal(); // true