write

Bun

Symbol

Socket.write

write(data: string | BufferSource, byteOffset?: number, byteLength?: number): number

Write data to the socket

@param data

The data to write to the socket

@param byteOffset

The offset in the buffer to start writing from (defaults to 0)

@param byteLength

The number of bytes to write (defaults to the length of the buffer)

When passed a string, byteOffset and byteLength refer to the UTF-8 offset, not the string character offset.

This is unbuffered as of Bun v0.2.2. That means individual write() calls will be slow. In the future, Bun will buffer writes and flush them at the end of the tick, when the event loop is idle, or sooner if the buffer is full.

Referenced types

type BufferSource = NodeJS.TypedArray | DataView | ArrayBufferLike