TLSSocket

external class TLSSocket : Socket(source)

Performs transparent encryption of written data and all required TLS negotiation.

Instances of tls.TLSSocket implement the duplex Stream interface.

Methods that return TLS connection metadata (e.g.{@link TLSSocket.getPeerCertificate}) will only return data while the connection is open.

Since

v0.11.4

Constructors

Link copied to clipboard
constructor(socket: Socket, options: TLSSocketOptions = definedExternally)

Construct a new tls.TLSSocket object from an existing TCP socket.

constructor(socket: Duplex, options: TLSSocketOptions = definedExternally)

Construct a new tls.TLSSocket object from an existing TCP socket.

Properties

Link copied to clipboard
open override val _construct: (callback: (JsError?) -> Unit) -> Unit?
Link copied to clipboard
open override val _writev: (chunks: Array<WritableWritevChunksItem>, callback: (JsError?) -> Unit) -> Unit?
Link copied to clipboard

If false then the stream will automatically end the writable side when the readable side ends. Set initially by the allowHalfOpen constructor option, which defaults to true.

Link copied to clipboard

String containing the selected ALPN protocol. Before a handshake has completed, this value is always null. When a handshake is completed but not ALPN protocol was selected, tlsSocket.alpnProtocol equals false.

Link copied to clipboard

Returns the reason why the peer's certificate was not been verified. This property is set only when tlsSocket.authorized === false.

Link copied to clipboard

This property is true if the peer certificate was signed by one of the CAs specified when creating the tls.TLSSocket instance, otherwise false.

Link copied to clipboard

This property is only present if the family autoselection algorithm is enabled in socket.connect(options) and it is an array of the addresses that have been attempted.

Link copied to clipboard

This property shows the number of characters buffered for writing. The buffer may contain strings whose length after encoding is not yet known. So this number is only an approximation of the number of bytes in the buffer.

Link copied to clipboard

The amount of received bytes.

Link copied to clipboard

The amount of bytes sent.

Link copied to clipboard
open override val closed: Boolean

Is true after 'close' has been emitted.

Link copied to clipboard

If true, socket.connect(options[, connectListener]) was called and has not yet finished. It will stay true until the socket becomes connected, then it is set to false and the 'connect' event is emitted. Note that the socket.connect(options[, connectListener]) callback is a listener for the 'connect' event.

Link copied to clipboard
open override var destroyed: Boolean

Is true after readable.destroy() has been called.

Link copied to clipboard
Link copied to clipboard

Always returns true. This may be used to distinguish TLS sockets from regularnet.Socket instances.

Link copied to clipboard
open override val errored: JsError?

Returns error if the stream has been destroyed with an error.

Link copied to clipboard

The string representation of the local IP address the remote client is connecting on. For example, in a server listening on '0.0.0.0', if a client connects on '192.168.1.1', the value of socket.localAddress would be'192.168.1.1'.

Link copied to clipboard

The string representation of the local IP family. 'IPv4' or 'IPv6'.

Link copied to clipboard

The numeric representation of the local port. For example, 80 or 21.

Link copied to clipboard

See writable.destroyed for further details.

Link copied to clipboard

This is true if the socket is not connected yet, either because .connect()has not yet been called or because it is still in the process of connecting (see socket.connecting).

Link copied to clipboard
open override var readable: Boolean

Is true if it is safe to call {@link read}, which means the stream has not been destroyed or emitted 'error' or 'end'.

Link copied to clipboard

Returns whether the stream was destroyed or errored before emitting 'end'.

Link copied to clipboard

Returns whether 'data' has been emitted.

Link copied to clipboard

Getter for the property encoding of a given Readable stream. The encoding property can be set using the {@link setEncoding} method.

Link copied to clipboard

Becomes true when 'end' event is emitted.

Link copied to clipboard

This property reflects the current state of a Readable stream as described in the Three states section.

Link copied to clipboard

Returns the value of highWaterMark passed when creating this Readable.

Link copied to clipboard

This property contains the number of bytes (or objects) in the queue ready to be read. The value provides introspection data regarding the status of the highWaterMark.

Link copied to clipboard

Getter for the property objectMode of a given Readable stream.

Link copied to clipboard

Is true if it is safe to call writable.write(), which means the stream has not been destroyed, errored, or ended.

Link copied to clipboard

This property represents the state of the connection as a string.

Link copied to clipboard

The string representation of the remote IP address. For example,'74.125.127.100' or '2001:4860:a005::68'. Value may be undefined if the socket is destroyed (for example, if the client disconnected).

Link copied to clipboard

The string representation of the remote IP family. 'IPv4' or 'IPv6'. Value may be undefined if the socket is destroyed (for example, if the client disconnected).

Link copied to clipboard

The numeric representation of the remote port. For example, 80 or 21. Value may be undefined if the socket is destroyed (for example, if the client disconnected).

Link copied to clipboard

The socket timeout in milliseconds as set by socket.setTimeout(). It is undefined if a timeout has not been set.

Link copied to clipboard
open override var writable: Boolean
Link copied to clipboard
open override val writableCorked: Double

Number of times writable.uncork() needs to be called in order to fully uncork the stream.

Link copied to clipboard
open override val writableEnded: Boolean

Is true after writable.end() has been called. This property does not indicate whether the data has been flushed, for this use writable.writableFinished instead.

Link copied to clipboard
open override val writableFinished: Boolean

Is set to true immediately before the 'finish' event is emitted.

Link copied to clipboard
open override val writableHighWaterMark: Double

Return the value of highWaterMark passed when creating this Writable.

Link copied to clipboard
open override val writableLength: Double

This property contains the number of bytes (or objects) in the queue ready to be written. The value provides introspection data regarding the status of the highWaterMark.

Link copied to clipboard
open override val writableNeedDrain: Boolean

Is true if the stream's buffer has been full and stream will emit 'drain'.

Link copied to clipboard
open override val writableObjectMode: Boolean

Getter for the property objectMode of a given Writable stream.

Functions

Link copied to clipboard
open override fun _destroy(error: JsError?, callback: (JsError?) -> Unit)
Link copied to clipboard
open override fun _final(callback: (JsError?) -> Unit)
Link copied to clipboard
fun _read(size: Number)
Link copied to clipboard
open override fun _write(chunk: Any?, encoding: BufferEncoding, callback: (JsError?) -> Unit)
Link copied to clipboard
fun addListener(event: SocketEvent.CLOSE, listener: (hadError: Boolean) -> Unit)
fun addListener(event: SocketEvent.CONNECT, listener: () -> Unit)
fun addListener(event: SocketEvent.CONNECTIONATTEMPT, listener: (ip: String, port: Double, family: Double) -> Unit)
fun addListener(event: SocketEvent.CONNECTIONATTEMPTFAILED, listener: (ip: String, port: Double, family: Double) -> Unit)
fun addListener(event: SocketEvent.CONNECTIONATTEMPTTIMEOUT, listener: (ip: String, port: Double, family: Double) -> Unit)
fun addListener(event: SocketEvent.DATA, listener: (data: Buffer) -> Unit)
fun addListener(event: SocketEvent.DRAIN, listener: () -> Unit)
fun addListener(event: SocketEvent.END, listener: () -> Unit)
fun addListener(event: SocketEvent.ERROR, listener: (JsError) -> Unit)
fun addListener(event: SocketEvent.LOOKUP, listener: (JsError, address: String, family: Any, host: String) -> Unit)
fun addListener(event: SocketEvent.READY, listener: () -> Unit)
fun addListener(event: SocketEvent.TIMEOUT, listener: () -> Unit)
open override fun addListener(event: Symbol, listener: Function<Unit>)
fun addListener(event: DuplexEvent.DATA, listener: (chunk: Any?) -> Unit)
fun addListener(event: DuplexEvent.DRAIN, listener: () -> Unit)
fun addListener(event: DuplexEvent.END, listener: () -> Unit)
fun addListener(event: DuplexEvent.ERROR, listener: (JsError) -> Unit)
fun addListener(event: DuplexEvent.FINISH, listener: () -> Unit)
fun addListener(event: DuplexEvent.PAUSE, listener: () -> Unit)
fun addListener(event: DuplexEvent.PIPE, listener: (src: Readable) -> Unit)
fun addListener(event: DuplexEvent.READABLE, listener: () -> Unit)
fun addListener(event: DuplexEvent.RESUME, listener: () -> Unit)
fun addListener(event: DuplexEvent.UNPIPE, listener: (src: Readable) -> Unit)
fun addListener(event: ReadableEvent.DATA, listener: (chunk: Any?) -> Unit)
fun addListener(event: ReadableEvent.END, listener: () -> Unit)
fun addListener(event: ReadableEvent.ERROR, listener: (JsError) -> Unit)
fun addListener(event: ReadableEvent.PAUSE, listener: () -> Unit)
fun addListener(event: ReadableEvent.READABLE, listener: () -> Unit)
fun addListener(event: ReadableEvent.RESUME, listener: () -> Unit)
fun addListener(event: WritableEvent.DRAIN, listener: () -> Unit)
fun addListener(event: WritableEvent.ERROR, listener: (JsError) -> Unit)
fun addListener(event: WritableEvent.FINISH, listener: () -> Unit)
fun addListener(event: WritableEvent.PIPE, listener: (src: Readable) -> Unit)
fun addListener(event: WritableEvent.UNPIPE, listener: (src: Readable) -> Unit)
fun addListener(event: TLSSocketEvent.KEYLOG, listener: (line: Buffer) -> Unit)
fun addListener(event: TLSSocketEvent.OCSPRESPONSE, listener: (response: Buffer) -> Unit)
fun addListener(event: TLSSocketEvent.SECURECONNECT, listener: () -> Unit)
fun addListener(event: TLSSocketEvent.SESSION, listener: (session: Buffer) -> Unit)

fun addListener(event: DuplexEvent.CLOSE, listener: () -> Unit)
fun addListener(event: ReadableEvent.CLOSE, listener: () -> Unit)
fun addListener(event: WritableEvent.CLOSE, listener: () -> Unit)

Event emitter The defined events on documents including:

open override fun addListener(event: String, listener: Function<Unit>)

events.EventEmitter

Link copied to clipboard
fun address(): Any

Returns the bound address, the address family name and port of the socket as reported by the operating system:{ port: 12346, family: 'IPv4', address: '127.0.0.1' }

Link copied to clipboard
fun asIndexedPairs(options: ArrayOptions = definedExternally): Readable

This method returns a new stream with chunks of the underlying stream paired with a counter in the form [index, chunk]. The first index value is 0 and it increases by 1 for each chunk produced.

Link copied to clipboard
open fun <T : ReadableStream> compose(stream: T, options: StreamComposeOptions = definedExternally): T
open fun <T : ReadableStream> compose(stream: AsyncIterable<T>, options: StreamComposeOptions = definedExternally): T
open fun <T : ReadableStream> compose(stream: JsIterable<T>, options: StreamComposeOptions = definedExternally): T
open fun <T : ReadableStream> compose(stream: ComposeFnParam, options: StreamComposeOptions = definedExternally): T
Link copied to clipboard
fun connect(options: SocketConnectOpts, connectionListener: () -> Unit = definedExternally)

Initiate a connection on a given socket.

fun connect(port: Number, connectionListener: () -> Unit = definedExternally)
fun connect(path: String, connectionListener: () -> Unit = definedExternally)
fun connect(port: Number, host: String, connectionListener: () -> Unit = definedExternally)
Link copied to clipboard
open override fun cork()

The writable.cork() method forces all written data to be buffered in memory. The buffered data will be flushed when either the {@link uncork} or {@link end} methods are called.

Link copied to clipboard
open override fun destroy()

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.

open override fun destroy(error: JsError)
Link copied to clipboard

Destroys the socket after all data is written. If the finish event was already emitted the socket is destroyed immediately. If the socket is still writable it implicitly calls socket.end().

Link copied to clipboard

Disables TLS renegotiation for this TLSSocket instance. Once called, attempts to renegotiate will trigger an 'error' event on the TLSSocket.

Link copied to clipboard
fun drop(limit: Number, options: ArrayOptions = definedExternally): Readable

This method returns a new stream with the first limit chunks dropped from the start.

Link copied to clipboard
fun emit(event: SocketEvent.CLOSE, hadError: Boolean): Boolean
fun emit(event: SocketEvent.DATA, data: Buffer): Boolean
fun emit(event: SocketEvent.CONNECTIONATTEMPT, ip: String, port: Number, family: Number): Boolean
fun emit(event: SocketEvent.LOOKUP, err: JsError, address: String, family: Double, host: String): Boolean
fun emit(event: SocketEvent.LOOKUP, err: JsError, address: String, family: String, host: String): Boolean
fun emit(event: DuplexEvent.DATA, chunk: Any?): Boolean
fun emit(event: ReadableEvent.DATA, chunk: Any?): Boolean
open override fun emit(event: Symbol, vararg args: Any?): Boolean
open override fun emit(event: String, vararg args: Any?): Boolean
fun emit(event: TLSSocketEvent.SESSION, session: Buffer): Boolean
Link copied to clipboard

When enabled, TLS packet trace information is written to stderr. This can be used to debug TLS connection problems.

Link copied to clipboard
open override fun end(cb: () -> Unit)

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

open override fun end(data: Uint8Array, cb: () -> Unit)
open override fun end(data: String, cb: () -> Unit)
fun end(str: Uint8Array, encoding: BufferEncoding = definedExternally, cb: () -> Unit = definedExternally)
open override fun end(str: String, encoding: BufferEncoding, cb: () -> Unit)
open override fun end(chunk: Any?, cb: () -> Unit)
open override fun end(chunk: Any?, encoding: BufferEncoding, cb: () -> Unit)
Link copied to clipboard

Returns an array listing the events for which the emitter has registered listeners. The values in the array are strings or Symbols.

Link copied to clipboard
fun every(fn: (data: Any?, options: ArrayOptions?) -> PromiseResult<Boolean>, options: ArrayOptions = definedExternally): Promise<Boolean>

This method is similar to Array.prototype.every and calls fn on each chunk in the stream to check if all awaited return values are truthy value for fn. Once an fn call on a chunk awaited return value is falsy, the stream is destroyed and the promise is fulfilled with false. If all of the fn calls on the chunks return a truthy value, the promise is fulfilled with true.

Link copied to clipboard
fun exportKeyingMaterial(length: Number, label: String, context: Buffer): Buffer

Keying material is used for validations to prevent different kind of attacks in network protocols, for example in the specifications of IEEE 802.1X.

Link copied to clipboard
fun filter(fn: (data: Any?, options: ArrayOptions?) -> PromiseResult<Boolean>, options: ArrayOptions = definedExternally): Readable

This method allows filtering the stream. For each chunk in the stream the fn function will be called and if it returns a truthy value, the chunk will be passed to the result stream. If the fn function returns a promise - that promise will be awaited.

Link copied to clipboard
fun find(fn: (data: Any?, options: ArrayOptions?) -> PromiseResult<Boolean>, options: ArrayOptions = definedExternally): Promise<Any?>

fun <T> find(fn: (data: Any?, options: ArrayOptions?) -> Boolean, options: ArrayOptions = definedExternally): Promise<T?>

This method is similar to Array.prototype.find and calls fn on each chunk in the stream to find a chunk with a truthy value for fn. Once an fn call's awaited return value is truthy, the stream is destroyed and the promise is fulfilled with value for which fn returned a truthy value. If all of the fn calls on the chunks return a falsy value, the promise is fulfilled with undefined.

Link copied to clipboard
fun flatMap(fn: (data: Any?, options: ArrayOptions?) -> Any?, options: ArrayOptions = definedExternally): Readable

This method returns a new stream by applying the given callback to each chunk of the stream and then flattening the result.

Link copied to clipboard
fun forEach(fn: (data: Any?, options: ArrayOptions?) -> PromiseResult<Void>, options: ArrayOptions = definedExternally): Promise<Void>

This method allows iterating a stream. For each chunk in the stream the fn function will be called. If the fn function returns a promise - that promise will be awaited.

Link copied to clipboard

Returns an object representing the local certificate. The returned object has some properties corresponding to the fields of the certificate.

Link copied to clipboard

Returns an object containing information on the negotiated cipher suite.

Link copied to clipboard

Returns an object representing the type, name, and size of parameter of an ephemeral key exchange in perfect forward secrecy on a client connection. It returns an empty object when the key exchange is not ephemeral. As this is only supported on a client socket; null is returned if called on a server socket. The supported types are 'DH' and 'ECDH'. The name property is available only when type is 'ECDH'.

Link copied to clipboard

As the Finished messages are message digests of the complete handshake (with a total of 192 bits for TLS 1.0 and more for SSL 3.0), they can be used for external authentication procedures when the authentication provided by SSL/TLS is not desired or is not enough.

Link copied to clipboard

Returns the current max listener value for the EventEmitter which is either set by emitter.setMaxListeners(n) or defaults to {@link defaultMaxListeners}.

Link copied to clipboard
fun getPeerCertificate(detailed: Boolean = definedExternally): Any

Returns an object representing the peer's certificate. If the peer does not provide a certificate, an empty object will be returned. If the socket has been destroyed, null will be returned.

Link copied to clipboard

As the Finished messages are message digests of the complete handshake (with a total of 192 bits for TLS 1.0 and more for SSL 3.0), they can be used for external authentication procedures when the authentication provided by SSL/TLS is not desired or is not enough.

Link copied to clipboard

Returns the peer certificate as an X509Certificate object.

Link copied to clipboard

Returns a string containing the negotiated SSL/TLS protocol version of the current connection. The value 'unknown' will be returned for connected sockets that have not completed the handshaking process. The value null will be returned for server sockets or disconnected client sockets.

Link copied to clipboard

Returns the TLS session data or undefined if no session was negotiated. On the client, the data can be provided to the session option of {@link connect} to resume the connection. On the server, it may be useful for debugging.

Link copied to clipboard
Link copied to clipboard

For a client, returns the TLS session ticket if one is available, orundefined. For a server, always returns undefined.

Link copied to clipboard

Returns the local certificate as an X509Certificate object.

Link copied to clipboard
open override fun isPaused(): Boolean

The readable.isPaused() method returns the current operating state of the Readable. This is used primarily by the mechanism that underlies the readable.pipe() method. In most typical cases, there will be no reason to use this method directly.

Link copied to clipboard

See Session Resumption for more information.

Link copied to clipboard
fun iterator(options: ReadableBaseIteratorOptions = definedExternally): AsyncIterator<Any?>

The iterator created by this method gives users the option to cancel the destruction of the stream if the for await...of loop is exited by return, break, or throw, or if the iterator should destroy the stream if the stream emitted an error during iteration.

Link copied to clipboard
fun map(fn: (data: Any?, options: ArrayOptions?) -> Any?, options: ArrayOptions = definedExternally): Readable

This method allows mapping over the stream. The fn function will be called for every chunk in the stream. If the fn function returns a promise - that promise will be awaited before being passed to the result stream.

Link copied to clipboard
fun on(event: SocketEvent.CLOSE, listener: (hadError: Boolean) -> Unit)
fun on(event: SocketEvent.CONNECT, listener: () -> Unit)
fun on(event: SocketEvent.CONNECTIONATTEMPT, listener: (ip: String, port: Double, family: Double) -> Unit)
fun on(event: SocketEvent.CONNECTIONATTEMPTFAILED, listener: (ip: String, port: Double, family: Double) -> Unit)
fun on(event: SocketEvent.CONNECTIONATTEMPTTIMEOUT, listener: (ip: String, port: Double, family: Double) -> Unit)
fun on(event: SocketEvent.DATA, listener: (data: Buffer) -> Unit)
fun on(event: SocketEvent.DRAIN, listener: () -> Unit)
fun on(event: SocketEvent.END, listener: () -> Unit)
fun on(event: SocketEvent.ERROR, listener: (JsError) -> Unit)
fun on(event: SocketEvent.LOOKUP, listener: (JsError, address: String, family: Any, host: String) -> Unit)
fun on(event: SocketEvent.READY, listener: () -> Unit)
fun on(event: SocketEvent.TIMEOUT, listener: () -> Unit)
open override fun on(event: Symbol, listener: Function<Unit>)
fun on(event: DuplexEvent.CLOSE, listener: () -> Unit)
fun on(event: DuplexEvent.DATA, listener: (chunk: Any?) -> Unit)
fun on(event: DuplexEvent.DRAIN, listener: () -> Unit)
fun on(event: DuplexEvent.END, listener: () -> Unit)
fun on(event: DuplexEvent.ERROR, listener: (JsError) -> Unit)
fun on(event: DuplexEvent.FINISH, listener: () -> Unit)
fun on(event: DuplexEvent.PAUSE, listener: () -> Unit)
fun on(event: DuplexEvent.PIPE, listener: (src: Readable) -> Unit)
fun on(event: DuplexEvent.READABLE, listener: () -> Unit)
fun on(event: DuplexEvent.RESUME, listener: () -> Unit)
fun on(event: DuplexEvent.UNPIPE, listener: (src: Readable) -> Unit)
fun on(event: ReadableEvent.CLOSE, listener: () -> Unit)
fun on(event: ReadableEvent.DATA, listener: (chunk: Any?) -> Unit)
fun on(event: ReadableEvent.END, listener: () -> Unit)
fun on(event: ReadableEvent.ERROR, listener: (JsError) -> Unit)
fun on(event: ReadableEvent.PAUSE, listener: () -> Unit)
fun on(event: ReadableEvent.READABLE, listener: () -> Unit)
fun on(event: ReadableEvent.RESUME, listener: () -> Unit)
fun on(event: WritableEvent.CLOSE, listener: () -> Unit)
fun on(event: WritableEvent.DRAIN, listener: () -> Unit)
fun on(event: WritableEvent.ERROR, listener: (JsError) -> Unit)
fun on(event: WritableEvent.FINISH, listener: () -> Unit)
fun on(event: WritableEvent.PIPE, listener: (src: Readable) -> Unit)
fun on(event: WritableEvent.UNPIPE, listener: (src: Readable) -> Unit)
open override fun on(event: String, listener: Function<Unit>)
fun on(event: TLSSocketEvent.KEYLOG, listener: (line: Buffer) -> Unit)
fun on(event: TLSSocketEvent.OCSPRESPONSE, listener: (response: Buffer) -> Unit)
fun on(event: TLSSocketEvent.SECURECONNECT, listener: () -> Unit)
fun on(event: TLSSocketEvent.SESSION, listener: (session: Buffer) -> Unit)
Link copied to clipboard
fun once(event: SocketEvent.CLOSE, listener: (hadError: Boolean) -> Unit)
fun once(event: SocketEvent.CONNECT, listener: () -> Unit)
fun once(event: SocketEvent.CONNECTIONATTEMPT, listener: (ip: String, port: Double, family: Double) -> Unit)
fun once(event: SocketEvent.CONNECTIONATTEMPTFAILED, listener: (ip: String, port: Double, family: Double) -> Unit)
fun once(event: SocketEvent.CONNECTIONATTEMPTTIMEOUT, listener: (ip: String, port: Double, family: Double) -> Unit)
fun once(event: SocketEvent.DATA, listener: (data: Buffer) -> Unit)
fun once(event: SocketEvent.DRAIN, listener: () -> Unit)
fun once(event: SocketEvent.END, listener: () -> Unit)
fun once(event: SocketEvent.ERROR, listener: (JsError) -> Unit)
fun once(event: SocketEvent.LOOKUP, listener: (JsError, address: String, family: Any, host: String) -> Unit)
fun once(event: SocketEvent.READY, listener: () -> Unit)
fun once(event: SocketEvent.TIMEOUT, listener: () -> Unit)
open override fun once(event: Symbol, listener: Function<Unit>)
fun once(event: DuplexEvent.CLOSE, listener: () -> Unit)
fun once(event: DuplexEvent.DATA, listener: (chunk: Any?) -> Unit)
fun once(event: DuplexEvent.DRAIN, listener: () -> Unit)
fun once(event: DuplexEvent.END, listener: () -> Unit)
fun once(event: DuplexEvent.ERROR, listener: (JsError) -> Unit)
fun once(event: DuplexEvent.FINISH, listener: () -> Unit)
fun once(event: DuplexEvent.PAUSE, listener: () -> Unit)
fun once(event: DuplexEvent.PIPE, listener: (src: Readable) -> Unit)
fun once(event: DuplexEvent.READABLE, listener: () -> Unit)
fun once(event: DuplexEvent.RESUME, listener: () -> Unit)
fun once(event: DuplexEvent.UNPIPE, listener: (src: Readable) -> Unit)
fun once(event: ReadableEvent.CLOSE, listener: () -> Unit)
fun once(event: ReadableEvent.DATA, listener: (chunk: Any?) -> Unit)
fun once(event: ReadableEvent.END, listener: () -> Unit)
fun once(event: ReadableEvent.ERROR, listener: (JsError) -> Unit)
fun once(event: ReadableEvent.PAUSE, listener: () -> Unit)
fun once(event: ReadableEvent.READABLE, listener: () -> Unit)
fun once(event: ReadableEvent.RESUME, listener: () -> Unit)
fun once(event: WritableEvent.CLOSE, listener: () -> Unit)
fun once(event: WritableEvent.DRAIN, listener: () -> Unit)
fun once(event: WritableEvent.ERROR, listener: (JsError) -> Unit)
fun once(event: WritableEvent.FINISH, listener: () -> Unit)
fun once(event: WritableEvent.PIPE, listener: (src: Readable) -> Unit)
fun once(event: WritableEvent.UNPIPE, listener: (src: Readable) -> Unit)
open override fun once(event: String, listener: Function<Unit>)
fun once(event: TLSSocketEvent.KEYLOG, listener: (line: Buffer) -> Unit)
fun once(event: TLSSocketEvent.OCSPRESPONSE, listener: (response: Buffer) -> Unit)
fun once(event: TLSSocketEvent.SECURECONNECT, listener: () -> Unit)
fun once(event: TLSSocketEvent.SESSION, listener: (session: Buffer) -> Unit)
Link copied to clipboard
open override fun pause()

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

Link copied to clipboard
open override fun <T : WritableStream> pipe(destination: T, options: ReadableStreamPipeOptions): T
fun <T : WritableStream> pipe(destination: T, options: StreamPipeOptions = definedExternally): T
Link copied to clipboard
fun prependListener(event: SocketEvent.CLOSE, listener: (hadError: Boolean) -> Unit)
fun prependListener(event: SocketEvent.CONNECT, listener: () -> Unit)
fun prependListener(event: SocketEvent.CONNECTIONATTEMPT, listener: (ip: String, port: Double, family: Double) -> Unit)
fun prependListener(event: SocketEvent.CONNECTIONATTEMPTFAILED, listener: (ip: String, port: Double, family: Double) -> Unit)
fun prependListener(event: SocketEvent.CONNECTIONATTEMPTTIMEOUT, listener: (ip: String, port: Double, family: Double) -> Unit)
fun prependListener(event: SocketEvent.DATA, listener: (data: Buffer) -> Unit)
fun prependListener(event: SocketEvent.DRAIN, listener: () -> Unit)
fun prependListener(event: SocketEvent.END, listener: () -> Unit)
fun prependListener(event: SocketEvent.ERROR, listener: (JsError) -> Unit)
fun prependListener(event: SocketEvent.LOOKUP, listener: (JsError, address: String, family: Any, host: String) -> Unit)
fun prependListener(event: SocketEvent.READY, listener: () -> Unit)
fun prependListener(event: SocketEvent.TIMEOUT, listener: () -> Unit)
open override fun prependListener(event: Symbol, listener: Function<Unit>)
fun prependListener(event: DuplexEvent.CLOSE, listener: () -> Unit)
fun prependListener(event: DuplexEvent.DATA, listener: (chunk: Any?) -> Unit)
fun prependListener(event: DuplexEvent.DRAIN, listener: () -> Unit)
fun prependListener(event: DuplexEvent.END, listener: () -> Unit)
fun prependListener(event: DuplexEvent.ERROR, listener: (JsError) -> Unit)
fun prependListener(event: DuplexEvent.FINISH, listener: () -> Unit)
fun prependListener(event: DuplexEvent.PAUSE, listener: () -> Unit)
fun prependListener(event: DuplexEvent.PIPE, listener: (src: Readable) -> Unit)
fun prependListener(event: DuplexEvent.READABLE, listener: () -> Unit)
fun prependListener(event: DuplexEvent.RESUME, listener: () -> Unit)
fun prependListener(event: DuplexEvent.UNPIPE, listener: (src: Readable) -> Unit)
fun prependListener(event: ReadableEvent.CLOSE, listener: () -> Unit)
fun prependListener(event: ReadableEvent.DATA, listener: (chunk: Any?) -> Unit)
fun prependListener(event: ReadableEvent.END, listener: () -> Unit)
fun prependListener(event: ReadableEvent.ERROR, listener: (JsError) -> Unit)
fun prependListener(event: ReadableEvent.PAUSE, listener: () -> Unit)
fun prependListener(event: ReadableEvent.READABLE, listener: () -> Unit)
fun prependListener(event: ReadableEvent.RESUME, listener: () -> Unit)
fun prependListener(event: WritableEvent.CLOSE, listener: () -> Unit)
fun prependListener(event: WritableEvent.DRAIN, listener: () -> Unit)
fun prependListener(event: WritableEvent.ERROR, listener: (JsError) -> Unit)
fun prependListener(event: WritableEvent.FINISH, listener: () -> Unit)
fun prependListener(event: WritableEvent.PIPE, listener: (src: Readable) -> Unit)
fun prependListener(event: WritableEvent.UNPIPE, listener: (src: Readable) -> Unit)
open override fun prependListener(event: String, listener: Function<Unit>)
fun prependListener(event: TLSSocketEvent.KEYLOG, listener: (line: Buffer) -> Unit)
fun prependListener(event: TLSSocketEvent.OCSPRESPONSE, listener: (response: Buffer) -> Unit)
fun prependListener(event: TLSSocketEvent.SESSION, listener: (session: Buffer) -> Unit)
Link copied to clipboard
fun prependOnceListener(event: SocketEvent.CLOSE, listener: (hadError: Boolean) -> Unit)
fun prependOnceListener(event: SocketEvent.CONNECT, listener: () -> Unit)
fun prependOnceListener(event: SocketEvent.CONNECTIONATTEMPT, listener: (ip: String, port: Double, family: Double) -> Unit)
fun prependOnceListener(event: SocketEvent.CONNECTIONATTEMPTFAILED, listener: (ip: String, port: Double, family: Double) -> Unit)
fun prependOnceListener(event: SocketEvent.CONNECTIONATTEMPTTIMEOUT, listener: (ip: String, port: Double, family: Double) -> Unit)
fun prependOnceListener(event: SocketEvent.DATA, listener: (data: Buffer) -> Unit)
fun prependOnceListener(event: SocketEvent.DRAIN, listener: () -> Unit)
fun prependOnceListener(event: SocketEvent.END, listener: () -> Unit)
fun prependOnceListener(event: SocketEvent.LOOKUP, listener: (JsError, address: String, family: Any, host: String) -> Unit)
fun prependOnceListener(event: SocketEvent.READY, listener: () -> Unit)
fun prependOnceListener(event: SocketEvent.TIMEOUT, listener: () -> Unit)
open override fun prependOnceListener(event: Symbol, listener: Function<Unit>)
fun prependOnceListener(event: DuplexEvent.CLOSE, listener: () -> Unit)
fun prependOnceListener(event: DuplexEvent.DATA, listener: (chunk: Any?) -> Unit)
fun prependOnceListener(event: DuplexEvent.DRAIN, listener: () -> Unit)
fun prependOnceListener(event: DuplexEvent.END, listener: () -> Unit)
fun prependOnceListener(event: DuplexEvent.FINISH, listener: () -> Unit)
fun prependOnceListener(event: DuplexEvent.PAUSE, listener: () -> Unit)
fun prependOnceListener(event: DuplexEvent.PIPE, listener: (src: Readable) -> Unit)
fun prependOnceListener(event: DuplexEvent.READABLE, listener: () -> Unit)
fun prependOnceListener(event: DuplexEvent.RESUME, listener: () -> Unit)
fun prependOnceListener(event: DuplexEvent.UNPIPE, listener: (src: Readable) -> Unit)
fun prependOnceListener(event: ReadableEvent.CLOSE, listener: () -> Unit)
fun prependOnceListener(event: ReadableEvent.DATA, listener: (chunk: Any?) -> Unit)
fun prependOnceListener(event: ReadableEvent.END, listener: () -> Unit)
fun prependOnceListener(event: ReadableEvent.PAUSE, listener: () -> Unit)
fun prependOnceListener(event: ReadableEvent.READABLE, listener: () -> Unit)
fun prependOnceListener(event: ReadableEvent.RESUME, listener: () -> Unit)
fun prependOnceListener(event: WritableEvent.CLOSE, listener: () -> Unit)
fun prependOnceListener(event: WritableEvent.DRAIN, listener: () -> Unit)
fun prependOnceListener(event: WritableEvent.FINISH, listener: () -> Unit)
fun prependOnceListener(event: WritableEvent.PIPE, listener: (src: Readable) -> Unit)
fun prependOnceListener(event: WritableEvent.UNPIPE, listener: (src: Readable) -> Unit)
open override fun prependOnceListener(event: String, listener: Function<Unit>)
fun prependOnceListener(event: TLSSocketEvent.KEYLOG, listener: (line: Buffer) -> Unit)
fun prependOnceListener(event: TLSSocketEvent.OCSPRESPONSE, listener: (response: Buffer) -> Unit)
fun prependOnceListener(event: TLSSocketEvent.SESSION, listener: (session: Buffer) -> Unit)
Link copied to clipboard
fun push(chunk: Any?, encoding: BufferEncoding = definedExternally): Boolean
Link copied to clipboard
open override fun read(size: Number): Any

Calls readable.destroy() with an AbortError and returns a promise that fulfills when the stream is finished.

Link copied to clipboard
open fun readOrNull(size: Number = definedExternally): Any?

The readable.read() method reads data out of the internal buffer and returns it. If no data is available to be read, null is returned. By default, the data is returned as a Buffer object unless an encoding has been specified using the readable.setEncoding() method or the stream is operating in object mode.

Link copied to clipboard
fun <T> reduce(fn: (previous: T, data: Any?, options: ArrayOptions?) -> T, initial: T, options: ArrayOptions = definedExternally): Promise<T>

fun <T> reduce(fn: (previous: Any?, data: Any?, options: ArrayOptions?) -> T, initial: Nothing? = definedExternally, options: ArrayOptions = definedExternally): Promise<T>

This method calls fn on each chunk of the stream in order, passing it the result from the calculation on the previous element. It returns a promise for the final value of the reduction.

Link copied to clipboard
fun ref()

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.

Link copied to clipboard
open override fun removeListener(event: Symbol, listener: Function<Unit>)
open override fun removeListener(event: String, listener: Function<Unit>)
fun removeListener(event: DuplexEvent.CLOSE, listener: () -> Unit)
fun removeListener(event: DuplexEvent.DATA, listener: (chunk: Any?) -> Unit)
fun removeListener(event: DuplexEvent.DRAIN, listener: () -> Unit)
fun removeListener(event: DuplexEvent.END, listener: () -> Unit)
fun removeListener(event: DuplexEvent.ERROR, listener: (JsError) -> Unit)
fun removeListener(event: DuplexEvent.FINISH, listener: () -> Unit)
fun removeListener(event: DuplexEvent.PAUSE, listener: () -> Unit)
fun removeListener(event: DuplexEvent.PIPE, listener: (src: Readable) -> Unit)
fun removeListener(event: DuplexEvent.READABLE, listener: () -> Unit)
fun removeListener(event: DuplexEvent.RESUME, listener: () -> Unit)
fun removeListener(event: DuplexEvent.UNPIPE, listener: (src: Readable) -> Unit)
fun removeListener(event: ReadableEvent.CLOSE, listener: () -> Unit)
fun removeListener(event: ReadableEvent.DATA, listener: (chunk: Any?) -> Unit)
fun removeListener(event: ReadableEvent.END, listener: () -> Unit)
fun removeListener(event: ReadableEvent.ERROR, listener: (JsError) -> Unit)
fun removeListener(event: ReadableEvent.PAUSE, listener: () -> Unit)
fun removeListener(event: ReadableEvent.READABLE, listener: () -> Unit)
fun removeListener(event: ReadableEvent.RESUME, listener: () -> Unit)
fun removeListener(event: WritableEvent.CLOSE, listener: () -> Unit)
fun removeListener(event: WritableEvent.DRAIN, listener: () -> Unit)
fun removeListener(event: WritableEvent.ERROR, listener: (JsError) -> Unit)
fun removeListener(event: WritableEvent.FINISH, listener: () -> Unit)
fun removeListener(event: WritableEvent.PIPE, listener: (src: Readable) -> Unit)
fun removeListener(event: WritableEvent.UNPIPE, listener: (src: Readable) -> Unit)
Link copied to clipboard

The tlsSocket.renegotiate() method initiates a TLS renegotiation process. Upon completion, the callback function will be passed a single argument that is either an Error (if the request failed) or null.

Link copied to clipboard

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.

Link copied to clipboard
open override fun resume()

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

Link copied to clipboard
open override fun setDefaultEncoding(encoding: BufferEncoding)

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

Link copied to clipboard
open override fun setEncoding(encoding: BufferEncoding)

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

Link copied to clipboard
fun setKeepAlive(enable: Boolean = definedExternally, initialDelay: Number = definedExternally)

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

Link copied to clipboard

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.

Link copied to clipboard

The tlsSocket.setMaxSendFragment() method sets the maximum TLS fragment size. Returns true if setting the limit succeeded; false otherwise.

Link copied to clipboard
fun setNoDelay(noDelay: Boolean = definedExternally)

Enable/disable the use of Nagle's algorithm.

Link copied to clipboard
fun setTimeout(timeout: Number, callback: () -> Unit = definedExternally)

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

Link copied to clipboard
fun some(fn: (data: Any?, options: ArrayOptions?) -> PromiseResult<Boolean>, options: ArrayOptions = definedExternally): Promise<Boolean>

This method is similar to Array.prototype.some and calls fn on each chunk in the stream until the awaited return value is true (or any truthy value). Once an fn call on a chunk awaited return value is truthy, the stream is destroyed and the promise is fulfilled with true. If none of the fn calls on the chunks return a truthy value, the promise is fulfilled with false.

Link copied to clipboard
fun take(limit: Number, options: ArrayOptions = definedExternally): Readable

This method returns a new stream with the first limit chunks.

Link copied to clipboard
fun toArray(options: ArrayOptions = definedExternally): Promise<ReadonlyArray<Any?>>

This method allows easily obtaining the contents of a stream.

Link copied to clipboard
open override fun uncork()

The writable.uncork() method flushes all data buffered since {@link cork} was called.

Link copied to clipboard
open override fun unpipe(destination: WritableStream)

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

Link copied to clipboard
fun unref()

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.

Link copied to clipboard
open override fun unshift(chunk: Uint8Array, encoding: BufferEncoding)
open override fun unshift(chunk: String, encoding: BufferEncoding)

fun unshift(chunk: Any?, encoding: BufferEncoding = definedExternally)

Passing chunk as null signals the end of the stream (EOF) and behaves the same as readable.push(null), after which no more data can be written. The EOF signal is put at the end of the buffer and any buffered data will still be flushed.

Link copied to clipboard
open override fun wrap(stream: ReadableStream)

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

Link copied to clipboard
open override fun write(buffer: Uint8Array, cb: (JsError?) -> Unit): Boolean
open override fun write(buffer: String, cb: (JsError?) -> Unit): Boolean

Sends data on the socket. The second parameter specifies the encoding in the case of a string. It defaults to UTF8 encoding.

fun write(str: Uint8Array, encoding: BufferEncoding = definedExternally, cb: (JsError?) -> Unit = definedExternally): Boolean
open override fun write(str: String, encoding: BufferEncoding, cb: (JsError?) -> Unit): Boolean
open override fun write(chunk: Any?, encoding: BufferEncoding, callback: (JsError?) -> Unit): Boolean

open override fun write(chunk: Any?, callback: (JsError?) -> Unit): Boolean

The writable.write() method writes some data to the stream, and calls the supplied callback once the data has been fully handled. If an error occurs, the callback will be called with the error as its first argument. The callback is called asynchronously and before 'error' is emitted.