Skip to content

buildWriteAsync

buildWriteAsync(): WriteAsync

Creates a WriteAsync function that writes data to a Node.js writable stream and properly handles backpressure.

When the underlying stream’s internal buffer is full, the function waits for the 'drain' event before resolving the promise, ensuring that subsequent writes do not overwhelm the stream.

WriteAsync

A WriteAsync function that writes chunks to the stream asynchronously.

const stream = createWriteStream('output.txt')
const writeAsync = buildWriteAsync()
await writeAsync(stream, 'Hello, World!')
await writeAsync(stream, 'Another line\n', 'utf8')
stream.end()