Creates a stream/iter Writer adapter from a classic Writable stream (or duck-typed equivalent). The adapter can be passed to pipeTo() as a destination.
Since all writes on a classic Writable are fundamentally asynchronous, the synchronous Writer methods (writeSync, writevSync, endSync) always return false or -1, deferring to the async path. The per-write options.signal parameter from the Writer interface is also ignored.
The result is cached per instance -- calling fromWritable() twice with the same stream returns the same Writer.
For duck-typed streams that do not expose writableHighWaterMark, writableLength, or similar properties, sensible defaults are used. Object-mode writables (if detectable) are rejected since the Writer interface is bytes-only.
import { Writable } from 'node:stream';
import { from, fromWritable, pipeTo } from 'node:stream/iter';
const writable = new Writable({
write(chunk, encoding, cb) { console.log(chunk.toString()); cb(); },
});
await pipeTo(from('hello world'),
fromWritable(writable, { backpressure: 'block' }));