Mend
Bun

method

Socket.end

data?: string | BufferSource,
byteOffset?: number,
byteLength?: number
): number;

Sends the final data chunk and initiates a graceful shutdown of the socket's write side. After calling end(), no more data can be written using write() or end(). The socket remains readable until the remote end also closes its write side or the connection is terminated. This sends a TCP FIN packet after writing the data.

@param data

Optional final data to write before closing. Same types as write().

@param byteOffset

Optional offset for buffer data.

@param byteLength

Optional length for buffer data.

@returns

The number of bytes written for the final chunk. Returns -1 if the socket was already closed or shutting down.

// send some data and close the write side
socket.end("Goodbye!");
// or close write side without sending final data
socket.end();
end(): void;

Close the socket immediately

Referenced types

type BufferSource = NodeJS.TypedArray | DataView | ArrayBufferLike