FtoWritable
Bun

function

stream.iter.toWritable

function toWritable(

Creates a classic stream.Writable backed by a stream/iter Writer.

Each _write() / _writev() call attempts the Writer's synchronous method first (writeSync / writevSync), falling back to the async method if the sync path returns false or throws. Similarly, _final() tries endSync() before end(). When the sync path succeeds, the callback is deferred via queueMicrotask to preserve the async resolution contract.

The Writable's highWaterMark is set to Number.MAX_SAFE_INTEGER to effectively disable its internal buffering, allowing the underlying Writer to manage backpressure directly.

import { push, toWritable } from 'node:stream/iter';

const { writer, readable } = push();
const writable = toWritable(writer);

writable.write('hello');
writable.end();
@param writer

A stream/iter Writer. Only the write() method is required; end(), fail(), writeSync(), writevSync(), endSync(), and writev() are optional.

Referenced types

interface PartialWriter