Skip to content

NodeSink

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 Added in v4.0.0 Source

Constructors

fromWritable

Added in v4.0.0 Source

Creates a Sink that writes chunks to a Node writable stream, respecting backpressure, mapping writable errors with onError, and ending the stream on completion unless endOnDone is false.

Signature

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

Creates a Channel that pulls chunks from upstream and writes them to a Node writable stream, respecting backpressure and optionally ending the writable when upstream is done.

Signature

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

Converting

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?: any;
  readonly endOnDone?: boolean;
  readonly onError: (error: unknown) => E;
  readonly pull: Pull<readonly [A, A], IE, unknown>;
  readonly writable: Writable;
}): Pull<never, IE | E, unknown>;