Skip to content

Stdout

[<Interface>]
type Stdout =
    [<Literal>] fd: float = 1
    abstract member fd: float with get, set
    abstract member ``end`` (str: U2<string,Uint8Array<U2<ArrayBuffer,SharedArrayBuffer>>>, ?encoding: BufferEncoding, ?callback: (unit -> unit)) : Stdout
    abstract member ``end`` (buffer: U2<string,Uint8Array<U2<ArrayBuffer,SharedArrayBuffer>>>, ?callback: (unit -> unit)) : Stdout
    abstract member ``end`` (?callback: (unit -> unit)) : Stdout
    abstract member addListener (event: string, listener: obj array -> unit) : Stdout
    abstract member addListenerResize (listener: unit -> unit) : Stdout
    abstract member compose<'T when 'T :> ReadableStream> (stream: U4<'T,AsyncIterable<'T,obj,obj>,(obj -> unit),Iterable<'T,obj,obj>>, ?options: Options) : 'T
    abstract member connect (path: string, ?connectionListener: (unit -> unit)) : Stdout
    abstract member connect (port: float, ?connectionListener: (unit -> unit)) : Stdout
    abstract member connect (port: float, host: string, ?connectionListener: (unit -> unit)) : Stdout
    abstract member connect (options: SocketConnectOpts, ?connectionListener: (unit -> unit)) : Stdout
    abstract member destroy (?error: exn) : Stdout
    abstract member off (eventName: U2<string,Symbol>, listener: obj array -> unit) : Stdout
    abstract member on (event: string, listener: obj array -> unit) : Stdout
    abstract member onResize (listener: unit -> unit) : Stdout
    abstract member once (event: string, listener: obj array -> unit) : Stdout
    abstract member onceResize (listener: unit -> unit) : Stdout
    abstract member pause () : Stdout
    abstract member pipe<'T when 'T :> WritableStream> (destination: 'T, ?options: Options) : 'T
    abstract member prependListener (event: string, listener: obj array -> unit) : Stdout
    abstract member prependListenerResize (listener: unit -> unit) : Stdout
    abstract member prependOnceListener (event: string, listener: obj array -> unit) : Stdout
    abstract member prependOnceListenerResize (listener: unit -> unit) : Stdout
    abstract member ref () : Stdout
    abstract member removeAllListeners (?eventName: U2<string,Symbol>) : Stdout
    abstract member removeListener (event: U2<string,Symbol>, listener: obj array -> unit) : Stdout
    abstract member removeListenerClose (listener: unit -> unit) : Stdout
    abstract member removeListenerData (listener: obj -> unit) : Stdout
    abstract member removeListenerDrain (listener: unit -> unit) : Stdout
    abstract member removeListenerEnd (listener: unit -> unit) : Stdout
    abstract member removeListenerError (listener: exn -> unit) : Stdout
    abstract member removeListenerFinish (listener: unit -> unit) : Stdout
    abstract member removeListenerPause (listener: unit -> unit) : Stdout
    abstract member removeListenerPipe (listener: Readable -> unit) : Stdout
    abstract member removeListenerReadable (listener: unit -> unit) : Stdout
    abstract member removeListenerResume (listener: unit -> unit) : Stdout
    abstract member removeListenerUnpipe (listener: Readable -> unit) : Stdout
    abstract member resetAndDestroy () : Stdout
    abstract member resume () : Stdout
    abstract member setDefaultEncoding (encoding: BufferEncoding) : Stdout
    abstract member setEncoding (?encoding: BufferEncoding) : Stdout
    abstract member setKeepAlive (?enable: bool, ?initialDelay: float) : Stdout
    abstract member setMaxListeners (n: float) : Stdout
    abstract member setNoDelay (?noDelay: bool) : Stdout
    abstract member setTimeout (timeout: float, ?callback: (unit -> unit)) : Stdout
    abstract member unpipe (?destination: WritableStream) : Stdout
    abstract member unref () : Stdout
    abstract member wrap (stream: ReadableStream) : Stdout
AssemblyXantham.Fable.Node
ImplementsWriteStream

Declared inside

Compose
Pipe

Functions and values

[<Literal>] fd: float = 1

TypeScript type: 1

Properties

abstract member fd: float with get, set

TypeScript type: 1

Methods

abstract member ``end`` (str: U2<string,Uint8Array<U2<ArrayBuffer,SharedArrayBuffer>>>, ?encoding: BufferEncoding, ?callback: (unit -> unit)) : Stdout

Half-closes the socket. i.e., it sends a FIN packet. It is possible the server will still send some data.

See writable.end() for further details. Half-closes the socket, with one final chunk of data.

@since v0.1.90

Parameter
callbackOptional callback for when the socket is finished.
callbackOptional callback for when the socket is finished.
encodingOnly used when data is string.
callbackOptional callback for when the socket is finished.

Returns. The socket itself.

abstract member ``end`` (buffer: U2<string,Uint8Array<U2<ArrayBuffer,SharedArrayBuffer>>>, ?callback: (unit -> unit)) : Stdout

Half-closes the socket. i.e., it sends a FIN packet. It is possible the server will still send some data.

See writable.end() for further details. Half-closes the socket, with one final chunk of data.

@since v0.1.90

Parameter
callbackOptional callback for when the socket is finished.
callbackOptional callback for when the socket is finished.
encodingOnly used when data is string.
callbackOptional callback for when the socket is finished.

Returns. The socket itself.

abstract member ``end`` (?callback: (unit -> unit)) : Stdout

Half-closes the socket. i.e., it sends a FIN packet. It is possible the server will still send some data.

See writable.end() for further details. Half-closes the socket, with one final chunk of data.

@since v0.1.90

Parameter
callbackOptional callback for when the socket is finished.
callbackOptional callback for when the socket is finished.
encodingOnly used when data is string.
callbackOptional callback for when the socket is finished.

Returns. The socket itself.

abstract member addListener (event: string, listener: obj array -> unit) : Stdout

events.EventEmitter

  1. close
  2. connect
  3. connectionAttempt
  4. connectionAttemptFailed
  5. connectionAttemptTimeout
  6. data
  7. drain
  8. end
  9. error
  10. lookup
  11. ready
  12. timeout
abstract member addListenerResize (listener: unit -> unit) : Stdout
addListener(event: "resize", listener: () => void): this
abstract member compose<'T when 'T :> ReadableStream> (stream: U4<'T,AsyncIterable<'T,obj,obj>,(obj -> unit),Iterable<'T,obj,obj>>, ?options: Options) : 'T
abstract member connect (path: string, ?connectionListener: (unit -> unit)) : Stdout

Initiate a connection on a given socket.

Possible signatures:

  • socket.connect(options[, connectListener])
  • socket.connect(path[, connectListener]) for IPC connections.
  • socket.connect(port[, host][, connectListener]) for TCP connections.
  • Returns: net.Socket The socket itself.

This function is asynchronous. When the connection is established, the 'connect' event will be emitted. If there is a problem connecting, instead of a 'connect' event, an 'error' event will be emitted with the error passed to the 'error' listener. The last parameter connectListener, if supplied, will be added as a listener for the 'connect' event once.

This function should only be used for reconnecting a socket after'close' has been emitted or otherwise it may lead to undefined behavior.

abstract member connect (port: float, ?connectionListener: (unit -> unit)) : Stdout

Initiate a connection on a given socket.

Possible signatures:

  • socket.connect(options[, connectListener])
  • socket.connect(path[, connectListener]) for IPC connections.
  • socket.connect(port[, host][, connectListener]) for TCP connections.
  • Returns: net.Socket The socket itself.

This function is asynchronous. When the connection is established, the 'connect' event will be emitted. If there is a problem connecting, instead of a 'connect' event, an 'error' event will be emitted with the error passed to the 'error' listener. The last parameter connectListener, if supplied, will be added as a listener for the 'connect' event once.

This function should only be used for reconnecting a socket after'close' has been emitted or otherwise it may lead to undefined behavior.

abstract member connect (port: float, host: string, ?connectionListener: (unit -> unit)) : Stdout

Initiate a connection on a given socket.

Possible signatures:

  • socket.connect(options[, connectListener])
  • socket.connect(path[, connectListener]) for IPC connections.
  • socket.connect(port[, host][, connectListener]) for TCP connections.
  • Returns: net.Socket The socket itself.

This function is asynchronous. When the connection is established, the 'connect' event will be emitted. If there is a problem connecting, instead of a 'connect' event, an 'error' event will be emitted with the error passed to the 'error' listener. The last parameter connectListener, if supplied, will be added as a listener for the 'connect' event once.

This function should only be used for reconnecting a socket after'close' has been emitted or otherwise it may lead to undefined behavior.

abstract member connect (options: SocketConnectOpts, ?connectionListener: (unit -> unit)) : Stdout

Initiate a connection on a given socket.

Possible signatures:

  • socket.connect(options[, connectListener])
  • socket.connect(path[, connectListener]) for IPC connections.
  • socket.connect(port[, host][, connectListener]) for TCP connections.
  • Returns: net.Socket The socket itself.

This function is asynchronous. When the connection is established, the 'connect' event will be emitted. If there is a problem connecting, instead of a 'connect' event, an 'error' event will be emitted with the error passed to the 'error' listener. The last parameter connectListener, if supplied, will be added as a listener for the 'connect' event once.

This function should only be used for reconnecting a socket after'close' has been emitted or otherwise it may lead to undefined behavior.

abstract member destroy (?error: exn) : Stdout

Destroy the stream. Optionally emit an 'error' event, and emit a 'close' event (unless emitClose is set to false). After this call, the readable stream will release any internal resources and subsequent calls to push() will be ignored.

Once destroy() has been called any further calls will be a no-op and no further errors except from _destroy() may be emitted as 'error'.

Implementors should not override this method, but instead implement readable._destroy().

@since v8.0.0

Parameter
errorError which will be passed as payload in 'error' event
abstract member off (eventName: U2<string,Symbol>, listener: obj array -> unit) : Stdout

Alias for emitter.removeListener().

@since v10.0.0

abstract member on (event: string, listener: obj array -> unit) : Stdout

Adds the listener function to the end of the listeners array for the event named eventName. No checks are made to see if the listener has already been added. Multiple calls passing the same combination of eventName and listener will result in the listener being added, and called, multiple times.

server.on('connection', (stream) => {
console.log('someone connected!');
});

Returns a reference to the EventEmitter, so that calls can be chained.

By default, event listeners are invoked in the order they are added. The emitter.prependListener() method can be used as an alternative to add the event listener to the beginning of the listeners array.

import { EventEmitter } from 'node:events';
const myEE = new EventEmitter();
myEE.on('foo', () => console.log('a'));
myEE.prependListener('foo', () => console.log('b'));
myEE.emit('foo');
// Prints:
//   b
//   a
abstract member onResize (listener: unit -> unit) : Stdout
on(event: "resize", listener: () => void): this
abstract member once (event: string, listener: obj array -> unit) : Stdout

Adds a one-timelistener function for the event named eventName. The next time eventName is triggered, this listener is removed and then invoked.

server.once('connection', (stream) => {
console.log('Ah, we have our first user!');
});

Returns a reference to the EventEmitter, so that calls can be chained.

By default, event listeners are invoked in the order they are added. The emitter.prependOnceListener() method can be used as an alternative to add the event listener to the beginning of the listeners array.

import { EventEmitter } from 'node:events';
const myEE = new EventEmitter();
myEE.once('foo', () => console.log('a'));
myEE.prependOnceListener('foo', () => console.log('b'));
myEE.emit('foo');
// Prints:
//   b
//   a
abstract member onceResize (listener: unit -> unit) : Stdout
once(event: "resize", listener: () => void): this
abstract member pause () : Stdout

Pauses the reading of data. That is, 'data' events will not be emitted. Useful to throttle back an upload.

Returns. The socket itself.

abstract member pipe<'T when 'T :> WritableStream> (destination: 'T, ?options: Options) : 'T
abstract member prependListener (event: string, listener: obj array -> unit) : Stdout

Adds the listener function to the beginning of the listeners array for the event named eventName. No checks are made to see if the listener has already been added. Multiple calls passing the same combination of eventName and listener will result in the listener being added, and called, multiple times.

server.prependListener('connection', (stream) => {
console.log('someone connected!');
});

Returns a reference to the EventEmitter, so that calls can be chained.

abstract member prependListenerResize (listener: unit -> unit) : Stdout
prependListener(event: "resize", listener: () => void): this
abstract member prependOnceListener (event: string, listener: obj array -> unit) : Stdout

Adds a one-timelistener function for the event named eventName to the beginning of the listeners array. The next time eventName is triggered, this listener is removed, and then invoked.

server.prependOnceListener('connection', (stream) => {
console.log('Ah, we have our first user!');
});

Returns a reference to the EventEmitter, so that calls can be chained.

abstract member prependOnceListenerResize (listener: unit -> unit) : Stdout
prependOnceListener(event: "resize", listener: () => void): this
abstract member ref () : Stdout

Opposite of unref(), calling ref() on a previously unrefed socket will not let the program exit if it's the only socket left (the default behavior). If the socket is refed calling ref again will have no effect.

@since v0.9.1

Returns. The socket itself.

abstract member removeAllListeners (?eventName: U2<string,Symbol>) : Stdout

Removes all listeners, or those of the specified eventName.

It is bad practice to remove listeners added elsewhere in the code, particularly when the EventEmitter instance was created by some other component or module (e.g. sockets or file streams).

Returns a reference to the EventEmitter, so that calls can be chained.

@since v0.1.26

abstract member removeListener (event: U2<string,Symbol>, listener: obj array -> unit) : Stdout

Removes the specified listener from the listener array for the event named eventName.

const callback = (stream) => {
console.log('someone connected!');
};
server.on('connection', callback);
// ...
server.removeListener('connection', callback);

removeListener() will remove, at most, one instance of a listener from the listener array. If any single listener has been added multiple times to the listener array for the specified eventName, then removeListener() must be called multiple times to remove each instance.

Once an event is emitted, all listeners attached to it at the time of emitting are called in order. This implies that any removeListener() or removeAllListeners() calls after emitting and before the last listener finishes execution will not remove them fromemit() in progress. Subsequent events behave as expected.

import { EventEmitter } from 'node:events';
class MyEmitter extends EventEmitter {}
const myEmitter = new MyEmitter();

const callbackA = () => {
console.log('A');
myEmitter.removeListener('event', callbackB);
};

const callbackB = () => {
console.log('B');
};

myEmitter.on('event', callbackA);

myEmitter.on('event', callbackB);

// callbackA removes listener callbackB but it will still be called.
// Internal listener array at time of emit [callbackA, callbackB]
myEmitter.emit('event');
// Prints:
//   A
//   B

// callbackB is now removed.
// Internal listener array [callbackA]
myEmitter.emit('event');
// Prints:
//   A

Because listeners are managed using an internal array, calling this will change the position indices of any listener registered after the listener being removed. This will not impact the order in which listeners are called, but it means that any copies of the listener array as returned by the emitter.listeners() method will need to be recreated.

When a single function has been added as a handler multiple times for a single event (as in the example below), removeListener() will remove the most recently added instance. In the example the once('ping') listener is removed:

import { EventEmitter } from 'node:events';
const ee = new EventEmitter();

function pong() {
console.log('pong');
}

ee.on('ping', pong);
ee.once('ping', pong);
ee.removeListener('ping', pong);

ee.emit('ping');
ee.emit('ping');

Returns a reference to the EventEmitter, so that calls can be chained.

abstract member removeListenerClose (listener: unit -> unit) : Stdout
removeListener(event: "close", listener: () => void): this
abstract member removeListenerData (listener: obj -> unit) : Stdout
removeListener(event: "data", listener: (chunk: any) => void): this
abstract member removeListenerDrain (listener: unit -> unit) : Stdout
removeListener(event: "drain", listener: () => void): this
abstract member removeListenerEnd (listener: unit -> unit) : Stdout
removeListener(event: "end", listener: () => void): this
abstract member removeListenerError (listener: exn -> unit) : Stdout
removeListener(event: "error", listener: (err: Error) => void): this
abstract member removeListenerFinish (listener: unit -> unit) : Stdout
removeListener(event: "finish", listener: () => void): this
abstract member removeListenerPause (listener: unit -> unit) : Stdout
removeListener(event: "pause", listener: () => void): this
abstract member removeListenerPipe (listener: Readable -> unit) : Stdout
removeListener(event: "pipe", listener: (src: Readable) => void): this
abstract member removeListenerReadable (listener: unit -> unit) : Stdout
removeListener(event: "readable", listener: () => void): this
abstract member removeListenerResume (listener: unit -> unit) : Stdout
removeListener(event: "resume", listener: () => void): this
abstract member removeListenerUnpipe (listener: Readable -> unit) : Stdout
removeListener(event: "unpipe", listener: (src: Readable) => void): this
abstract member resetAndDestroy () : Stdout

Close the TCP connection by sending an RST packet and destroy the stream. If this TCP socket is in connecting status, it will send an RST packet and destroy this TCP socket once it is connected. Otherwise, it will call socket.destroy with an ERR_SOCKET_CLOSED Error. If this is not a TCP socket (for example, a pipe), calling this method will immediately throw an ERR_INVALID_HANDLE_TYPE Error.

@since v18.3.0, v16.17.0

abstract member resume () : Stdout

Resumes reading after a call to socket.pause().

Returns. The socket itself.

abstract member setDefaultEncoding (encoding: BufferEncoding) : Stdout

The writable.setDefaultEncoding() method sets the default encoding for a Writable stream.

@since v0.11.15

Parameter
encodingThe new default encoding
abstract member setEncoding (?encoding: BufferEncoding) : Stdout

Set the encoding for the socket as a Readable Stream. See readable.setEncoding() for more information.

@since v0.1.90

Returns. The socket itself.

abstract member setKeepAlive (?enable: bool, ?initialDelay: float) : Stdout

Enable/disable keep-alive functionality, and optionally set the initial delay before the first keepalive probe is sent on an idle socket.

Set initialDelay (in milliseconds) to set the delay between the last data packet received and the first keepalive probe. Setting 0 forinitialDelay will leave the value unchanged from the default (or previous) setting.

Enabling the keep-alive functionality will set the following socket options:

  • SO_KEEPALIVE=1
  • TCP_KEEPIDLE=initialDelay
  • TCP_KEEPCNT=10
  • TCP_KEEPINTVL=1

@since v0.1.92

Returns. The socket itself.

abstract member setMaxListeners (n: float) : Stdout

By default EventEmitters will print a warning if more than 10 listeners are added for a particular event. This is a useful default that helps finding memory leaks. The emitter.setMaxListeners() method allows the limit to be modified for this specific EventEmitter instance. The value can be set to Infinity (or 0) to indicate an unlimited number of listeners.

Returns a reference to the EventEmitter, so that calls can be chained.

@since v0.3.5

abstract member setNoDelay (?noDelay: bool) : Stdout

Enable/disable the use of Nagle's algorithm.

When a TCP connection is created, it will have Nagle's algorithm enabled.

Nagle's algorithm delays data before it is sent via the network. It attempts to optimize throughput at the expense of latency.

Passing true for noDelay or not passing an argument will disable Nagle's algorithm for the socket. Passing false for noDelay will enable Nagle's algorithm.

@since v0.1.90

Returns. The socket itself.

abstract member setTimeout (timeout: float, ?callback: (unit -> unit)) : Stdout

Sets the socket to timeout after timeout milliseconds of inactivity on the socket. By default net.Socket do not have a timeout.

When an idle timeout is triggered the socket will receive a 'timeout' event but the connection will not be severed. The user must manually call socket.end() or socket.destroy() to end the connection.

socket.setTimeout(3000);
socket.on('timeout', () => {
console.log('socket timeout');
socket.end();
});

If timeout is 0, then the existing idle timeout is disabled.

The optional callback parameter will be added as a one-time listener for the 'timeout' event.

@since v0.1.90

Returns. The socket itself.

abstract member unpipe (?destination: WritableStream) : Stdout

The readable.unpipe() method detaches a Writable stream previously attached using the pipe method.

If the destination is not specified, then all pipes are detached.

If the destination is specified, but no pipe is set up for it, then the method does nothing.

import fs from 'node:fs';
const readable = getReadableStreamSomehow();
const writable = fs.createWriteStream('file.txt');
// All the data from readable goes into 'file.txt',
// but only for the first second.
readable.pipe(writable);
setTimeout(() => {
console.log('Stop writing to file.txt.');
readable.unpipe(writable);
console.log('Manually close the file stream.');
writable.end();
}, 1000);

@since v0.9.4

Parameter
destinationOptional specific stream to unpipe
abstract member unref () : Stdout

Calling unref() on a socket will allow the program to exit if this is the only active socket in the event system. If the socket is already unrefed callingunref() again will have no effect.

@since v0.9.1

Returns. The socket itself.

abstract member wrap (stream: ReadableStream) : Stdout

Prior to Node.js 0.10, streams did not implement the entire node:stream module API as it is currently defined. (See Compatibility for more information.)

When using an older Node.js library that emits 'data' events and has a pause method that is advisory only, the readable.wrap() method can be used to create a Readable stream that uses the old stream as its data source.

It will rarely be necessary to use readable.wrap() but the method has been provided as a convenience for interacting with older Node.js applications and libraries.

import { OldReader } from './old-api-module.js';
import { Readable } from 'node:stream';
const oreader = new OldReader();
const myReader = new Readable().wrap(oreader);

myReader.on('readable', () => {
myReader.read(); // etc.
});

@since v0.9.4

Parameter
streamAn "old style" readable stream