Skip to content
Effect 4.0 is here. One ecosystem. Zero dependencies.

NodeSink unstable

Sink adapters for writing Effect chunks into Node writable streams.

fromWritable creates a Sink, fromWritableChannel creates a lower-level Channel, and pullIntoWritable writes from an existing pull loop. All three adapters respect writable-stream backpressure, map writable errors with the supplied onError function, and can end the writable when the upstream data is done.

3 exports Since v4.0.0 Source

Constructors

Since v4.0.0

Creates a Sink that writes chunks to a Node writable stream, respecting backpressure and mapping writable errors with onError. Unless endOnDone is false, the writable is ended on completion and destroyed on upstream failure or interruption.

Signature

declare function fromWritable<E, A = string | Uint8Array<ArrayBufferLike>>(options: {
readonly encoding?: BufferEncoding;
readonly endOnDone?: boolean;
readonly evaluate: LazyArg<Writable | WritableStream>;
readonly onError: (error: unknown) => E;
}): Sink<void, A, never, E>
Since v4.0.0

Creates a Channel that pulls chunks from upstream and writes them to a Node writable stream, respecting backpressure. Unless endOnDone is false, the writable is ended when upstream is done and destroyed on upstream failure or interruption.

Signature

declare function fromWritableChannel<IE, E, A = string | Uint8Array<ArrayBufferLike>>(options: {
readonly encoding?: BufferEncoding;
readonly endOnDone?: boolean;
readonly evaluate: LazyArg<Writable | WritableStream>;
readonly onError: (error: unknown) => E;
}): Channel<never, IE | E, void, readonly [A, A], IE>

Converting

Since v4.0.0

Writes Effect chunks into a Node writable stream.

When to use

Use to implement custom Node stream adapters that already have an upstream pull and need direct control over a writable stream.

Details

The loop waits for drain when needed, fails on writable errors, and ends the writable on upstream completion unless endOnDone is false.

Signature

declare function pullIntoWritable<A, IE, E>(options: {
readonly encoding?: BufferEncoding;
readonly endOnDone?: boolean;
readonly onError: (error: unknown) => E;
readonly pull: Pull<readonly [A, A], IE, unknown>;
readonly writable: Writable;
}): Pull<never, IE | E, unknown>